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" 210e2c34f92f00628d48968dfea096d36381f494cbStephen Hines#include "llvm/ADT/iterator.h" 22651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "llvm/ADT/iterator_range.h" 23aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 24aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/PrettyStackTrace.h" 250ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 260ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace clang { 279852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ASTMutationListener; 289852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass BlockDecl; 29d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidisclass CXXRecordDecl; 309852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass CompoundStmt; 319852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass DeclContext; 329852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass DeclarationName; 339852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass DependentDiagnostic; 34b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass EnumDecl; 359852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass FunctionDecl; 36651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesclass FunctionType; 376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesenum Linkage : unsigned char; 38dc0705645276258afddb06cdf0fd7c8840251ee0Rafael Espindolaclass LinkageComputer; 399852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass LinkageSpecDecl; 40ca2ab45341c448284cf93770018c717810575f86Douglas Gregorclass Module; 419852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass NamedDecl; 429852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass NamespaceDecl; 430701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryDecl; 440701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroffclass ObjCCategoryImplDecl; 459852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCContainerDecl; 46bfb498d0996ef049efe9476f2802976fd145cd60Argyrios Kyrtzidisclass ObjCImplDecl; 479852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCImplementationDecl; 489852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCInterfaceDecl; 499852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCMethodDecl; 509852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass ObjCProtocolDecl; 519852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerstruct PrintingPolicy; 52176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hinesclass RecordDecl; 539852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass Stmt; 540c01d18094100db92d38daa923c95661512db203John McCallclass StoredDeclsMap; 554967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainarclass TemplateDecl; 569852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass TranslationUnitDecl; 579852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramerclass UsingDirectiveDecl; 580eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner} 590eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner 600eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattnernamespace clang { 610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 620a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Captures the result of checking the availability of a 630a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// declaration. 640a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor enum AvailabilityResult { 650a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_Available = 0, 660a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_NotYetIntroduced, 670a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_Deprecated, 680a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor AR_Unavailable 690a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor }; 700a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Decl - This represents one declaration (or definition), e.g. a variable, 721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typedef, function, struct, etc. 730ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 7487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar/// Note: There are objects tacked on before the *beginning* of Decl 7587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar/// (and its subclasses) in its Decl::operator new(). Proper alignment 764967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar/// of all subclasses (not requiring more than the alignment of Decl) is 7787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar/// asserted in DeclBase.cpp. 784967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainarclass LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl { 790ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 8064650af7cc4352c6c67b9bd1bf8ef3ce7471b910Douglas Gregor /// \brief Lists the kind of concrete classes of Decl. 810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum Kind { 829a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define DECL(DERIVED, BASE) DERIVED, 839a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define ABSTRACT_DECL(DECL) 849a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define DECL_RANGE(BASE, START, END) \ 859a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE = START, last##BASE = END, 869a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#define LAST_DECL_RANGE(BASE, START, END) \ 879a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt first##BASE = START, last##BASE = END 889a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt#include "clang/AST/DeclNodes.inc" 890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 900ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 916ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner /// \brief A placeholder type used to construct an empty shell of a 926ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner /// decl-derived type that will be filled in later (e.g., by some 936ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner /// deserialization method). 946ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner struct EmptyShell { }; 956ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner 960d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// IdentifierNamespace - The different namespaces in which 970d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// declarations may appear. According to C99 6.2.3, there are 980d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// four namespaces, labels, tags, members and ordinary 990d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// identifiers. C++ describes lookup completely differently: 1000d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// certain lookups merely "ignore" certain kinds of declarations, 1010d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// usually based on whether the declaration is of a type, etc. 102ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// 1030d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// These are meant as bitmasks, so that searches in 1040d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// C++ can look into the "tag" namespace during ordinary lookup. 1050d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// 10607a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl /// Decl currently provides 15 bits of IDNS bits. 1070ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum IdentifierNamespace { 1080d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Labels, declared with 'x:' and referenced with 'goto x'. 1090d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall IDNS_Label = 0x0001, 1100d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall 1110d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// Tags, declared with 'struct foo;' and referenced with 1120d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// 'struct foo'. All tags are also types. This is what 1130d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall /// elaborated-type-specifiers look for in C. 1144967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// This also contains names that conflict with tags in the 1154967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// same scope but that are otherwise ordinary names (non-type 1164967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// template parameters and indirect field declarations). 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, 1354967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// member, or function-local extern 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. 160a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IDNS_NonMemberOperator = 0x0400, 161a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith 162a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// This declaration is a function-local extern declaration of a 163a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// variable or function. This may also be IDNS_Ordinary if it 1644967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// has been declared outside any function. These act mostly like 1654967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// invisible friend declarations, but are also visible to unqualified 1664967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// lookup within the scope of the declaring function. 1674967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar IDNS_LocalExtern = 0x0800, 1684967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 1694967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// This declaration is an OpenMP user defined reduction construction. 1704967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar IDNS_OMPReduction = 0x1000 1710ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 1721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17309e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// ObjCDeclQualifier - 'Qualifiers' written next to the return and 17409e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// parameter types in method declarations. Other than remembering 17509e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// them and mangling them into the method's signature string, these 17609e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// are ignored by the compiler; they are consumed by certain 17709e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// remote-messaging frameworks. 17809e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// 17909e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// in, inout, and out are mutually exclusive and apply only to 18009e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// method parameters. bycopy and byref are mutually exclusive and 18109e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// apply only to method parameters (?). oneway applies only to 18209e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// results. All of these expect their corresponding parameter to 18309e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// have a particular type. None of this is currently enforced by 18409e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// clang. 18509e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// 18609e2c524a18435211cfbc2fb355f91e1ac43ea89John McCall /// This should be kept in sync with ObjCDeclSpec::ObjCDeclQualifier. 1870ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner enum ObjCDeclQualifier { 1880ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_None = 0x0, 1890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_In = 0x1, 1900ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Inout = 0x2, 1910ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Out = 0x4, 1920ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Bycopy = 0x8, 1930ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner OBJC_TQ_Byref = 0x10, 19487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar OBJC_TQ_Oneway = 0x20, 19587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 19687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// The nullability qualifier is set when the nullability of the 19787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// result or parameter was expressed via a context-sensitive 19887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// keyword. 19987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar OBJC_TQ_CSNullability = 0x40 2000ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner }; 2011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20246cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregorprotected: 20346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor // Enumeration values used in the bits stored in NextInContextAndBits. 20446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor enum { 20546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief Whether this declaration is a top-level declaration (function, 20646cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// global variable, etc.) that is lexically inside an objc container 20746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// definition. 20846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor TopLevelDeclInObjCContainerFlag = 0x01, 20946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor 21046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief Whether this declaration is private to the module in which it was 21146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// defined. 21246cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor ModulePrivateFlag = 0x02 21346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor }; 21446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor 21546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief The next declaration within the same lexical 2164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclContext. These pointers form the linked list that is 2174afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// traversed via DeclContext's decls_begin()/decls_end(). 21846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// 21946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// The extra two bits are used for the TopLevelDeclInObjCContainer and 22046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// ModulePrivate bits. 22146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor llvm::PointerIntPair<Decl *, 2, unsigned> NextInContextAndBits; 2224afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 22346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregorprivate: 2244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor friend class DeclContext; 2254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 226ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner struct MultipleDC { 227ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner DeclContext *SemanticDC; 228ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner DeclContext *LexicalDC; 229ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner }; 2301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2324afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 2334afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations that don't contain C++ scope specifiers, it contains 2344afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// the DeclContext where the Decl was declared. 2354afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// For declarations with C++ scope specifiers, it contains a MultipleDC* 2364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// with the context where it semantically belongs (SemanticDC) and the 2374afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// context where it was lexically declared (LexicalDC). 2384afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 2394afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 2404afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 2414afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 2424afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 2434afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 2444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 245ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; 2464afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 247ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } 248ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } 2494afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor inline MultipleDC *getMultipleDC() const { 250ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner return DeclCtx.get<MultipleDC*>(); 2514afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 25210d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner inline DeclContext *getSemanticDC() const { 253ee219fd5f2776d8dd39d857f87304297b5ed743aChris Lattner return DeclCtx.get<DeclContext*>(); 25410d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner } 2551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 256381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor /// Loc - The location of this decl. 25739d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar SourceLocation Loc; 2581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2590ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 2604967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar unsigned DeclKind : 7; 2611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// InvalidDecl - This indicates a semantic error occurred. 26335043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned InvalidDecl : 1; 2641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2650ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// HasAttrs - This indicates whether the decl has attributes or not. 26635043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned HasAttrs : 1; 267d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 2686b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// Implicit - Whether this declaration was implicitly generated by 2696b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// the implementation rather than explicitly written by the user. 27035043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned Implicit : 1; 2716b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 272e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// \brief Whether this declaration was "used", meaning that a definition is 273e0762c92110dfdcdd207db461a4ea17afd168f1eDouglas Gregor /// required. 27435043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned Used : 1; 2759cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregor 2766b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// \brief Whether this declaration was "referenced". 2776b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// The difference with 'Used' is whether the reference appears in a 2786b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// evaluated context or not, e.g. functions used in uninstantiated templates 2796b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis /// are regarded as "referenced" but not "used". 2806b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis unsigned Referenced : 1; 281ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 28202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar /// \brief Whether statistic collection is enabled. 28302892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static bool StatisticsEnabled; 28402892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar 2859cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregorprotected: 2867d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor /// Access - Used by C++ decls for the access specifier. 2877d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 2887d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor unsigned Access : 2; 2897d1d49d2971b20a97b3c2a301470b9eaaa130137Douglas Gregor friend class CXXClassMemberWrapper; 2900b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl 29108e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor /// \brief Whether this declaration was loaded from an AST file. 29208e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor unsigned FromASTFile : 1; 293ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 294f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor /// \brief Whether this declaration is hidden from normal name lookup, e.g., 295f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor /// because it is was loaded from an AST file is either module-private or 296f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor /// because its submodule has not been made visible. 297f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor unsigned Hidden : 1; 298f143ffc4a9af79ac1d822fea6995af4bf45d17dcDouglas Gregor 299769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. 3004967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar unsigned IdentifierNamespace : 13; 3011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 302a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola /// \brief If 0, we have not computed the linkage of this declaration. 303a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola /// Otherwise, it is the linkage + 1. 304a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola mutable unsigned CacheValidAndLinkage : 3; 305ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3068d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor friend class ASTDeclWriter; 3078d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor friend class ASTDeclReader; 308ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor friend class ASTReader; 309dc0705645276258afddb06cdf0fd7c8840251ee0Rafael Espindola friend class LinkageComputer; 3108d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor 31122050f25e34ba0cd21ee2dc3d765951c48e27cdeRichard Smith template<typename decl_type> friend class Redeclarable; 31222050f25e34ba0cd21ee2dc3d765951c48e27cdeRichard Smith 313651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Allocate memory for a deserialized declaration. 314651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// 315651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// This routine must be used to allocate memory for any declaration that is 316651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// deserialized from a module file. 317651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// 318651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \param Size The size of the allocated object. 319651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \param Ctx The context in which we will allocate memory. 320651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \param ID The global ID of the deserialized declaration. 321651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \param Extra The amount of extra space to allocate after the object. 322651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void *operator new(std::size_t Size, const ASTContext &Ctx, unsigned ID, 323651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::size_t Extra = 0); 324651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 325651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Allocate memory for a non-deserialized declaration. 326651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void *operator new(std::size_t Size, const ASTContext &Ctx, 327651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines DeclContext *Parent, std::size_t Extra = 0); 328651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 3299cfbe48a7a20a217fdb2920b29b67ae7941cb116Douglas Gregorprivate: 330651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool AccessDeclContextSanity() const; 3311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3324afa39deaa245592977136d367251ee2c173dd8dDouglas Gregorprotected: 333d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis 3341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Decl(Kind DK, DeclContext *DC, SourceLocation L) 33546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor : NextInContextAndBits(), DeclCtx(DC), 33639d7650656fdd1be879ed7d0c722cfeae95e56d5Daniel Dunbar Loc(L), DeclKind(DK), InvalidDecl(0), 3376b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis HasAttrs(false), Implicit(false), Used(false), Referenced(false), 338b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar Access(AS_none), FromASTFile(0), Hidden(DC && cast<Decl>(DC)->Hidden), 339381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 340a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola CacheValidAndLinkage(0) 341381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor { 34202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) add(DK); 3430ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 3441bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishop 3456764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis Decl(Kind DK, EmptyShell Empty) 34646cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor : NextInContextAndBits(), DeclKind(DK), InvalidDecl(0), 3476b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis HasAttrs(false), Implicit(false), Used(false), Referenced(false), 34846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Access(AS_none), FromASTFile(0), Hidden(0), 349381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 350a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola CacheValidAndLinkage(0) 351381d34e0b205ca27bcc7e7c1652561941c437965Douglas Gregor { 35202892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar if (StatisticsEnabled) add(DK); 3536764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis } 3546764334dfa73d67cbbb1b1fc8fe00440aad00f2aArgyrios Kyrtzidis 355da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual ~Decl(); 356da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor 3576bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor /// \brief Update a potentially out-of-date declaration. 3586bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor void updateOutOfDate(IdentifierInfo &II) const; 3596bd992946bda92193fadce7e4890d4465d2702f4Douglas Gregor 360a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola Linkage getCachedLinkage() const { 361a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola return Linkage(CacheValidAndLinkage - 1); 362a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola } 363a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola 364a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola void setCachedLinkage(Linkage L) const { 365a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola CacheValidAndLinkage = L + 1; 366a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola } 367a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola 368a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola bool hasCachedLinkage() const { 369a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola return CacheValidAndLinkage; 370a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola } 371a99ecbcc4c431d52df0b01539035ab5281d54656Rafael Espindola 3721bb19638f2ec0d63ed131b51ca8d9542d1a9afeeSam Bishoppublic: 37355d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 37455d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis /// \brief Source range that this declaration covers. 375aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar virtual SourceRange getSourceRange() const LLVM_READONLY { 376da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor return SourceRange(getLocation(), getLocation()); 377da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor } 378aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY { 379aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar return getSourceRange().getBegin(); 380aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar } 381aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY { 382aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar return getSourceRange().getEnd(); 383aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar } 38455d608cbadf1e9c05064f9287c057d50b7df65b4Argyrios Kyrtzidis 3850ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner SourceLocation getLocation() const { return Loc; } 3860ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner void setLocation(SourceLocation L) { Loc = L; } 3870ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 38835043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall Kind getKind() const { return static_cast<Kind>(DeclKind); } 3890ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner const char *getDeclKindName() const; 3901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Decl *getNextDeclInContext() { return NextInContextAndBits.getPointer(); } 39246cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor const Decl *getNextDeclInContext() const {return NextInContextAndBits.getPointer();} 39396f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner 3944afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor DeclContext *getDeclContext() { 39510d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner if (isInSemaDC()) 39610d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getSemanticDC(); 39710d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getMultipleDC()->SemanticDC; 3984afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 3990cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getDeclContext() const { 4000cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<Decl*>(this)->getDeclContext(); 4010cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner } 4023708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis 403f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall /// Find the innermost non-closure ancestor of this declaration, 404f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall /// walking up through blocks, lambdas, etc. If that ancestor is 405f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall /// not a code context (!isFunctionOrMethod()), returns null. 406f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall /// 407f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall /// A declaration may be its own non-closure context. 408f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall Decl *getNonClosureContext(); 409f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall const Decl *getNonClosureContext() const { 410aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall return const_cast<Decl*>(this)->getNonClosureContext(); 411aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall } 412aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall 4133708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis TranslationUnitDecl *getTranslationUnitDecl(); 4143708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis const TranslationUnitDecl *getTranslationUnitDecl() const { 4153708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis return const_cast<Decl*>(this)->getTranslationUnitDecl(); 4163708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis } 4173708b3df2e86998dca4c006939014ea1174da834Argyrios Kyrtzidis 4189aeed32282fe8a775c24c01c923717ca86695685John McCall bool isInAnonymousNamespace() const; 4199aeed32282fe8a775c24c01c923717ca86695685John McCall 4206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isInStdNamespace() const; 4216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 422aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar ASTContext &getASTContext() const LLVM_READONLY; 4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4241329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson void setAccess(AccessSpecifier AS) { 4251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Access = AS; 426651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines assert(AccessDeclContextSanity()); 4271329c274628cc8c4e8ad472b41d1a78c8123f611Anders Carlsson } 4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump AccessSpecifier getAccess() const { 430651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines assert(AccessDeclContextSanity()); 4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return AccessSpecifier(Access); 432b8547e800f9553a72c2f3635ae2371692bd4411aAnders Carlsson } 4334afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 434109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor /// \brief Retrieve the access specifier for this declaration, even though 435109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor /// it may not yet have been properly set. 436109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor AccessSpecifier getAccessUnsafe() const { 437109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor return AccessSpecifier(Access); 438109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor } 439109f5fc8dff6f3bd707e0e4140dc99ef7d4f3e88Douglas Gregor 44076a642ff4fce7a0648c79a1f01324a8c3880e251Chris Lattner bool hasAttrs() const { return HasAttrs; } 4414bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis void setAttrs(const AttrVec& Attrs) { 4424bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis return setAttrsImpl(Attrs, getASTContext()); 4434bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis } 444ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AttrVec &getAttrs() { 445cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs()); 44681abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattner } 447cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt const AttrVec &getAttrs() const; 448cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt void dropAttrs(); 4490ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 450b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor void addAttr(Attr *A) { 451b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor if (hasAttrs()) 452b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor getAttrs().push_back(A); 453b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor else 454b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor setAttrs(AttrVec(1, A)); 455b5f35bae05f1ce3ae62ca52b266a086fd019e89bDouglas Gregor } 4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 457cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt typedef AttrVec::const_iterator attr_iterator; 458651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<attr_iterator> attr_range; 459651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 460651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines attr_range attrs() const { 461651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return attr_range(attr_begin(), attr_end()); 462651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 463cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 464cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt attr_iterator attr_begin() const { 4656bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return hasAttrs() ? getAttrs().begin() : nullptr; 466cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 467cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt attr_iterator attr_end() const { 4686bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return hasAttrs() ? getAttrs().end() : nullptr; 469cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 470ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 471c3ca14d13741889a9b924d0ca32e818f07a9834aFariborz Jahanian template <typename T> 4728cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian void dropAttr() { 4738cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian if (!HasAttrs) return; 474ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 47510be5bad483cfe66bb5eb5ff948c03c4628ce774Benjamin Kramer AttrVec &Vec = getAttrs(); 47610be5bad483cfe66bb5eb5ff948c03c4628ce774Benjamin Kramer Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa<T, Attr*>), Vec.end()); 47710be5bad483cfe66bb5eb5ff948c03c4628ce774Benjamin Kramer 47810be5bad483cfe66bb5eb5ff948c03c4628ce774Benjamin Kramer if (Vec.empty()) 4798cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian HasAttrs = false; 4808cf0f52037e0c4bf656953ae63a07e8156aeb5fbFariborz Jahanian } 481ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 482cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt template <typename T> 483651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines llvm::iterator_range<specific_attr_iterator<T>> specific_attrs() const { 48487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return llvm::make_range(specific_attr_begin<T>(), specific_attr_end<T>()); 485651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 486651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 487651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines template <typename T> 488cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt specific_attr_iterator<T> specific_attr_begin() const { 489cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return specific_attr_iterator<T>(attr_begin()); 490cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 491cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt template <typename T> 492cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt specific_attr_iterator<T> specific_attr_end() const { 493cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return specific_attr_iterator<T>(attr_end()); 494cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 495cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 496cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt template<typename T> T *getAttr() const { 4976bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : nullptr; 498cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 49940b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis template<typename T> bool hasAttr() const { 500cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt return hasAttrs() && hasSpecificAttr<T>(getAttrs()); 501cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt } 502cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 503cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt /// getMaxAlignment - return the maximum alignment specified by attributes 504cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt /// on this decl, 0 if there are none. 5052fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramer unsigned getMaxAlignment() const; 5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5070ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// setInvalidDecl - Indicates the Decl had a semantic error. This 5080ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// allows for graceful error recovery. 50942738573253da1bd61f9c44f8d77f600d3b0cd1cDouglas Gregor void setInvalidDecl(bool Invalid = true); 5100ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isInvalidDecl() const { return (bool) InvalidDecl; } 5116b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor 5126b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// isImplicit - Indicates whether the declaration was implicitly 5136b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// generated by the implementation. If false, this declaration 5146b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor /// was written explicitly in the source code. 5156b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor bool isImplicit() const { return Implicit; } 5166b3945f4bc757bdadd3e443180cf32c2cccb52a0Douglas Gregor void setImplicit(bool I = true) { Implicit = I; } 5171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5184967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// \brief Whether *any* (re-)declaration of the entity was used, meaning that 5194967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// a definition is required. 520c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// 521c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// \param CheckUsedAttr When true, also consider the "used" attribute 522c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// (in addition to the "used" bit set by \c setUsed()) when determining 523c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor /// whether the function is used. 524c070cc602d6eefea881f71a60de09e05b54c3fddDouglas Gregor bool isUsed(bool CheckUsedAttr = true) const; 525cf807c4dfdb23e8fa3f400e0b24ef5b79db7a530Sean Hunt 52686164e8f51fa89a3ec904607c3848dc4a21b12cfEli Friedman /// \brief Set whether the declaration is used, in the sense of odr-use. 52786164e8f51fa89a3ec904607c3848dc4a21b12cfEli Friedman /// 52886164e8f51fa89a3ec904607c3848dc4a21b12cfEli Friedman /// This should only be used immediately after creating a declaration. 5294967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// It intentionally doesn't notify any listeners. 5304967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar void setIsUsed() { getCanonicalDecl()->Used = true; } 53186164e8f51fa89a3ec904607c3848dc4a21b12cfEli Friedman 53286164e8f51fa89a3ec904607c3848dc4a21b12cfEli Friedman /// \brief Mark the declaration used, in the sense of odr-use. 53386164e8f51fa89a3ec904607c3848dc4a21b12cfEli Friedman /// 53486164e8f51fa89a3ec904607c3848dc4a21b12cfEli Friedman /// This notifies any mutation listeners in addition to setting a bit 53586164e8f51fa89a3ec904607c3848dc4a21b12cfEli Friedman /// indicating the declaration is used. 53686164e8f51fa89a3ec904607c3848dc4a21b12cfEli Friedman void markUsed(ASTContext &C); 5371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 538176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief Whether any declaration of this entity was referenced. 5396b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis bool isReferenced() const; 5406b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis 541176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief Whether this declaration was referenced. This should not be relied 542176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// upon for anything other than debugging. 543176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool isThisDeclarationReferenced() const { return Referenced; } 544176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 5456b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis void setReferenced(bool R = true) { Referenced = R; } 5466b6b42aed07726178f61954ac6e51f47da00275cArgyrios Kyrtzidis 547c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis /// \brief Whether this declaration is a top-level declaration (function, 548c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis /// global variable, etc.) that is lexically inside an objc container 549c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis /// definition. 550c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis bool isTopLevelDeclInObjCContainer() const { 55146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor return NextInContextAndBits.getInt() & TopLevelDeclInObjCContainerFlag; 552c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis } 553c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis 554c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis void setTopLevelDeclInObjCContainer(bool V = true) { 55546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor unsigned Bits = NextInContextAndBits.getInt(); 55646cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor if (V) 55746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Bits |= TopLevelDeclInObjCContainerFlag; 55846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor else 55946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Bits &= ~TopLevelDeclInObjCContainerFlag; 56046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor NextInContextAndBits.setInt(Bits); 56146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor } 56246cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor 56346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief Whether this declaration was marked as being private to the 56446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// module in which it was defined. 565b775100fea6d8955149897dae1adca50ca471d17Richard Smith bool isModulePrivate() const { 56646cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor return NextInContextAndBits.getInt() & ModulePrivateFlag; 56746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor } 568b775100fea6d8955149897dae1adca50ca471d17Richard Smith 5694967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Return true if this declaration has an attribute which acts as 5704967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// definition of the entity, such as 'alias' or 'ifunc'. 5714967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar bool hasDefiningAttr() const; 5724967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 5734967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Return this declaration's defining attribute if it has one. 5744967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar const Attr *getDefiningAttr() const; 5754967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 576b775100fea6d8955149897dae1adca50ca471d17Richard Smithprotected: 57746cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// \brief Specify whether this declaration was marked as being private 57846cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor /// to the module in which it was defined. 57946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor void setModulePrivate(bool MP = true) { 58046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor unsigned Bits = NextInContextAndBits.getInt(); 58146cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor if (MP) 58246cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Bits |= ModulePrivateFlag; 58346cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor else 58446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor Bits &= ~ModulePrivateFlag; 58546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor NextInContextAndBits.setInt(Bits); 586c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis } 587c14a03dffff69b5e1c55cc118fc52d8fd9f3a28dArgyrios Kyrtzidis 588c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor /// \brief Set the owning module ID. 589c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor void setOwningModuleID(unsigned ID) { 590c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor assert(isFromASTFile() && "Only works on a deserialized declaration"); 591c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor *((unsigned*)this - 2) = ID; 592c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor } 593c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 59446cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregorpublic: 59546cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor 5960a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine the availability of the given declaration. 5970a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 5980a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// This routine will determine the most restrictive availability of 5990a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// the given declaration (e.g., preferring 'unavailable' to 6000a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 'deprecated'). 6010a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 6020a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param Message If non-NULL and the result is not \c 6030a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// AR_Available, will be set to a (possibly empty) message 6040a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// describing why the declaration has not been introduced, is 6050a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// deprecated, or is unavailable. 6066bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines AvailabilityResult getAvailability(std::string *Message = nullptr) const; 6070a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 6080a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine whether this declaration is marked 'deprecated'. 6090a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 6100a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param Message If non-NULL and the declaration is deprecated, 6110a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// this will be set to the message describing why the declaration 6120a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// was deprecated (which may be empty). 6136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isDeprecated(std::string *Message = nullptr) const { 6140a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor return getAvailability(Message) == AR_Deprecated; 6150a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor } 6160a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 6170a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine whether this declaration is marked 'unavailable'. 6180a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 6190a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param Message If non-NULL and the declaration is unavailable, 6200a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// this will be set to the message describing why the declaration 6210a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// was made unavailable (which may be empty). 6226bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isUnavailable(std::string *Message = nullptr) const { 6230a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor return getAvailability(Message) == AR_Unavailable; 6240a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor } 6250a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 6260a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determine whether this is a weak-imported symbol. 6270a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 6280a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// Weak-imported symbols are typically marked with the 6297f3ad231bed2184694e407772689e8903068bdcaEli Friedman /// 'weak_import' attribute, but may also be marked with an 6300a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 'availability' attribute where we're targing a platform prior to 6310a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// the introduction of this feature. 6320a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool isWeakImported() const; 6330a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 6340a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \brief Determines whether this symbol can be weak-imported, 6350a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// e.g., whether it would be well-formed to add the weak_import 6360a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// attribute. 6370a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// 6380a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// \param IsDefinition Set to \c true to indicate that this 6390a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor /// declaration cannot be weak-imported because it has a definition. 6400a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor bool canBeWeakImported(bool &IsDefinition) const; 6410a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor 642919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor /// \brief Determine whether this declaration came from an AST file (such as 643919814def90acecd25a35445862f0c0ff72a9b05Douglas Gregor /// a precompiled header or module) rather than having been parsed. 64408e0bc16b3312c27e87d33be7dcf3d4fe5bdd2e2Douglas Gregor bool isFromASTFile() const { return FromASTFile; } 645ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 646b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor /// \brief Retrieve the global declaration ID associated with this 647b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor /// declaration, which specifies where in the 648b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor unsigned getGlobalID() const { 649b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor if (isFromASTFile()) 650b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor return *((const unsigned*)this - 1); 651b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor return 0; 652b6b60c1521a2e65f60e93c5fd56c103cf027df63Douglas Gregor } 653c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 654c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor /// \brief Retrieve the global ID of the module that owns this particular 655c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor /// declaration. 656c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor unsigned getOwningModuleID() const { 657c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor if (isFromASTFile()) 658c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor return *((const unsigned*)this - 2); 659c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor 660c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor return 0; 661c6c8e0ec96bb64f1b9f543d7c8317c6090f80a30Douglas Gregor } 662ca2ab45341c448284cf93770018c717810575f86Douglas Gregor 663ca2ab45341c448284cf93770018c717810575f86Douglas Gregorprivate: 664ca2ab45341c448284cf93770018c717810575f86Douglas Gregor Module *getOwningModuleSlow() const; 665b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainarprotected: 666b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar bool hasLocalOwningModuleStorage() const; 667ca2ab45341c448284cf93770018c717810575f86Douglas Gregor 668ca2ab45341c448284cf93770018c717810575f86Douglas Gregorpublic: 669b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \brief Get the imported owning module, if this decl is from an imported 670b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// (non-local) module. 671b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar Module *getImportedOwningModule() const { 672ca2ab45341c448284cf93770018c717810575f86Douglas Gregor if (!isFromASTFile()) 6736bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 674ca2ab45341c448284cf93770018c717810575f86Douglas Gregor 675ca2ab45341c448284cf93770018c717810575f86Douglas Gregor return getOwningModuleSlow(); 676ca2ab45341c448284cf93770018c717810575f86Douglas Gregor } 677ca2ab45341c448284cf93770018c717810575f86Douglas Gregor 678b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// \brief Get the local owning module, if known. Returns nullptr if owner is 679b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar /// not yet known or declaration is not from a module. 680b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar Module *getLocalOwningModule() const { 681b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar if (isFromASTFile() || !Hidden) 682b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar return nullptr; 683b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar return reinterpret_cast<Module *const *>(this)[-1]; 684b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar } 685b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar void setLocalOwningModule(Module *M) { 686b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar assert(!isFromASTFile() && Hidden && hasLocalOwningModuleStorage() && 687b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar "should not have a cached owning module"); 688b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar reinterpret_cast<Module **>(this)[-1] = M; 689b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar } 690b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar 691cc636688c4fd10b1732ce3e33b2b106024d545caDouglas Gregor unsigned getIdentifierNamespace() const { 692769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner return IdentifierNamespace; 6930ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 694d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner bool isInIdentifierNamespace(unsigned NS) const { 695d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner return getIdentifierNamespace() & NS; 696d62fdc448b3ace606c8c9c9f13e43218fa204dbfChris Lattner } 697769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner static unsigned getIdentifierNamespaceForKind(Kind DK); 698769dbdf467681f6020ff248b969c2d41a4fdccd3Chris Lattner 6990d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall bool hasTagIdentifierNamespace() const { 7000d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall return isTagIdentifierNamespace(getIdentifierNamespace()); 7010d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall } 7020d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall static bool isTagIdentifierNamespace(unsigned NS) { 7030d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall // TagDecls have Tag and Type set and may also have TagFriend. 7040d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type); 7050d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall } 7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7074afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getLexicalDeclContext - The declaration context where this Decl was 7084afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// lexically declared (LexicalDC). May be different from 7094afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// getDeclContext() (SemanticDC). 7104afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// e.g.: 7114afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// 7124afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// namespace A { 7134afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void f(); // SemanticDC == LexicalDC == 'namespace A' 7144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// } 7154afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// void A::f(); // SemanticDC == namespace 'A' 7164afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// // LexicalDC == global namespace 71710d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner DeclContext *getLexicalDeclContext() { 7184afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor if (isInSemaDC()) 71910d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return getSemanticDC(); 7204afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor return getMultipleDC()->LexicalDC; 7214afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 72210d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner const DeclContext *getLexicalDeclContext() const { 72310d8379676f32b493740a5509e2cd7f0d6433139Chris Lattner return const_cast<Decl*>(this)->getLexicalDeclContext(); 7244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor } 725f5cecfbdcd20be224861f9e67c5973a9a2b61512Argyrios Kyrtzidis 726176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Determine whether this declaration is declared out of line (outside its 727176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// semantic context). 728176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines virtual bool isOutOfLine() const; 7291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7306ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// setDeclContext - Set both the semantic and lexical DeclContext 7316ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor /// to DC. 7326ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor void setDeclContext(DeclContext *DC); 7336ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor 7344afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor void setLexicalDeclContext(DeclContext *DC); 7354afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 7367a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this 7377a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// scoped decl is defined outside the current function or method. This is 7387a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// roughly global variables and functions, but also handles enums (which 7397a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// could be defined inside or outside a function etc). 740c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis bool isDefinedOutsideFunctionOrMethod() const { 7416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return getParentFunctionOrMethod() == nullptr; 742c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis } 743c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis 74487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief Returns true if this declaration lexically is inside a function. 74587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// It recognizes non-defining declarations as well as members of local 74687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// classes: 74787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \code 74887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// void foo() { void bar(); } 74987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// void foo2() { class ABC { void bar(); }; } 75087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \endcode 75187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool isLexicallyWithinFunctionOrMethod() const; 75287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 753c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis /// \brief If this decl is defined inside a function/method/block it returns 754c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis /// the corresponding DeclContext, otherwise it returns null. 755c8680f46970a5a53d07e05edd93657e64764da3cArgyrios Kyrtzidis const DeclContext *getParentFunctionOrMethod() const; 756fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis DeclContext *getParentFunctionOrMethod() { 757fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis return const_cast<DeclContext*>( 758fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis const_cast<const Decl*>(this)->getParentFunctionOrMethod()); 759fcc1e50ebcb441c6c610ccd539f57c57549bd66cArgyrios Kyrtzidis } 7604afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 761b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis /// \brief Retrieves the "canonical" declaration of the given declaration. 762da2142f2e2b3a02ee6eb5de9f9e6ed6f7eb5a0c0Douglas Gregor virtual Decl *getCanonicalDecl() { return this; } 763b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis const Decl *getCanonicalDecl() const { 764b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis return const_cast<Decl*>(this)->getCanonicalDecl(); 765b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis } 766fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis 767ac4e3794c60fc194fb2bd9764aa81d4cae530eccArgyrios Kyrtzidis /// \brief Whether this particular Decl is a canonical one. 768b57a4fe73b8227c0dba651818b8495dfca61e530Argyrios Kyrtzidis bool isCanonicalDecl() const { return getCanonicalDecl() == this; } 769c896ad064fd6ee73a7e0536d94df77b2cc7313b6Douglas Gregor 7701e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidisprotected: 7711e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Returns the next redeclaration or itself if this is the only decl. 7721e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// 7731e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Decl subclasses that can be redeclared should override this method so that 7741e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Decl::redecl_iterator can iterate over them. 7756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual Decl *getNextRedeclarationImpl() { return this; } 7761e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 777ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// \brief Implementation of getPreviousDecl(), to be overridden by any 778ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// subclass that has a redeclaration chain. 7796bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual Decl *getPreviousDeclImpl() { return nullptr; } 7806bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 781ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// \brief Implementation of getMostRecentDecl(), to be overridden by any 7826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// subclass that has a redeclaration chain. 783ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor virtual Decl *getMostRecentDeclImpl() { return this; } 7846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 7851e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidispublic: 7861e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// \brief Iterates through all the redeclarations of the same decl. 7871e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis class redecl_iterator { 7881e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis /// Current - The current declaration. 7891e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Current; 7901e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis Decl *Starter; 7911e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 7921e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis public: 793581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef Decl *value_type; 794581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef const value_type &reference; 795581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef const value_type *pointer; 7961e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis typedef std::forward_iterator_tag iterator_category; 797581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef std::ptrdiff_t difference_type; 7981e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 7996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines redecl_iterator() : Current(nullptr) { } 8001e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { } 8011e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 802581deb3da481053c4993c7600f97acf7768caac5David Blaikie reference operator*() const { return Current; } 803581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator->() const { return Current; } 8041e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 8051e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator& operator++() { 8061e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis assert(Current && "Advancing while iterator has reached end"); 8071e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis // Get either previous decl or latest decl. 8086bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Decl *Next = Current->getNextRedeclarationImpl(); 80922cbd2b794676c3b29c2b401c26730ed7047809eArgyrios Kyrtzidis assert(Next && "Should return next redeclaration or itself, never null!"); 8106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines Current = (Next != Starter) ? Next : nullptr; 8111e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return *this; 8121e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 8131e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 8141e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator operator++(int) { 8151e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator tmp(*this); 8161e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis ++(*this); 8171e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return tmp; 8181e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 8191e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 8201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator==(redecl_iterator x, redecl_iterator y) { 8211e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return x.Current == y.Current; 8221e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator!=(redecl_iterator x, redecl_iterator y) { 8241e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis return x.Current != y.Current; 8251e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 8261e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis }; 8271e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis 828651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<redecl_iterator> redecl_range; 829651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 830651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Returns an iterator range for all the redeclarations of the same 831651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// decl. It will iterate at least once (when this decl is the only one). 832651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines redecl_range redecls() const { 833651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return redecl_range(redecls_begin(), redecls_end()); 834651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 835651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 8361e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator redecls_begin() const { 837651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return redecl_iterator(const_cast<Decl *>(this)); 8381e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis } 8391e4bc099882626059f14d687ed7a1a5518b7f3c2Argyrios Kyrtzidis redecl_iterator redecls_end() const { return redecl_iterator(); } 840fc7e2a8fbb08f0f496ac6cea0721fe72db8ce240Argyrios Kyrtzidis 841f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor /// \brief Retrieve the previous declaration that declares the same entity 842f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor /// as this declaration, or NULL if there is no previous declaration. 843ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor Decl *getPreviousDecl() { return getPreviousDeclImpl(); } 844f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor 845f785a7d611404cf4747287a2bbc59b4d0e6a5a8cDouglas Gregor /// \brief Retrieve the most recent declaration that declares the same entity 846ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// as this declaration, or NULL if there is no previous declaration. 847ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor const Decl *getPreviousDecl() const { 848ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor return const_cast<Decl *>(this)->getPreviousDeclImpl(); 849ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor } 8507693b32af6863c63fcaf4de087760740ee675f71Rafael Espindola 851e6ddd7f610cf6caf3b5691b0f3d60e00e8c95741Rafael Espindola /// \brief True if this is the first declaration in its redeclaration chain. 8527693b32af6863c63fcaf4de087760740ee675f71Rafael Espindola bool isFirstDecl() const { 8536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return getPreviousDecl() == nullptr; 8547693b32af6863c63fcaf4de087760740ee675f71Rafael Espindola } 8557693b32af6863c63fcaf4de087760740ee675f71Rafael Espindola 856ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// \brief Retrieve the most recent declaration that declares the same entity 857ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// as this declaration (which may be this declaration). 858ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor Decl *getMostRecentDecl() { return getMostRecentDeclImpl(); } 859ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor 860ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// \brief Retrieve the most recent declaration that declares the same entity 861ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor /// as this declaration (which may be this declaration). 862ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor const Decl *getMostRecentDecl() const { 863ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor return const_cast<Decl *>(this)->getMostRecentDeclImpl(); 864ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor } 865ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor 866d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// getBody - If this Decl represents a declaration for a body of code, 867d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// such as a function or method definition, this method returns the 868d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// top-level Stmt* of that body. Otherwise this method returns null. 8696bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual Stmt* getBody() const { return nullptr; } 870d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 871a438e68ad7da48e7e4903785e5e96732abcdadfbManuel Klimek /// \brief Returns true if this \c Decl represents a declaration for a body of 87206a54a38be5054c910ffc92db60edab23f9ea105Argyrios Kyrtzidis /// code, such as a function or method definition. 873a438e68ad7da48e7e4903785e5e96732abcdadfbManuel Klimek /// Note that \c hasBody can also return true if any redeclaration of this 874a438e68ad7da48e7e4903785e5e96732abcdadfbManuel Klimek /// \c Decl represents a declaration for a body of code. 8756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual bool hasBody() const { return getBody() != nullptr; } 87606a54a38be5054c910ffc92db60edab23f9ea105Argyrios Kyrtzidis 877d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// getBodyRBrace - Gets the right brace of the body, if a body exists. 878d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl /// This works whether the body is a CompoundStmt or a CXXTryStmt. 8796fb0aee4f9dc261bbec72e1283ad8dc0557a6d96Argyrios Kyrtzidis SourceLocation getBodyRBrace() const; 880d3a413d3b8eb39bcee5944bc545d9997c1abe492Sebastian Redl 8810ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner // global temp stats (until we have a per-module visitor) 8829a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt static void add(Kind k); 88302892a65b18875a04c7ed5eadb3a13be801ab477Daniel Dunbar static void EnableStatistics(); 8840ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner static void PrintStats(); 8851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 88667e332009c6e349dc34700f539747afcff990336Anders Carlsson /// isTemplateParameter - Determines whether this declaration is a 887f57172b24f08a68d179675989813d5479dc87829Douglas Gregor /// template parameter. 888f57172b24f08a68d179675989813d5479dc87829Douglas Gregor bool isTemplateParameter() const; 8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89067e332009c6e349dc34700f539747afcff990336Anders Carlsson /// isTemplateParameter - Determines whether this declaration is a 89167e332009c6e349dc34700f539747afcff990336Anders Carlsson /// template parameter pack. 89267e332009c6e349dc34700f539747afcff990336Anders Carlsson bool isTemplateParameterPack() const; 893f57172b24f08a68d179675989813d5479dc87829Douglas Gregor 8941fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor /// \brief Whether this declaration is a parameter pack. 8951fe85ea697fb5c85acded3ac0ddbc19f89c2e181Douglas Gregor bool isParameterPack() const; 896ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 897ed9d84a2112e2bd56befb5f4fa8fc5bdf71fafa3Caitlin Sadowski /// \brief returns true if this declaration is a template 898ed9d84a2112e2bd56befb5f4fa8fc5bdf71fafa3Caitlin Sadowski bool isTemplateDecl() const; 899ed9d84a2112e2bd56befb5f4fa8fc5bdf71fafa3Caitlin Sadowski 900e53060fa78ad7e98352049f72787bdb7543e2a48Douglas Gregor /// \brief Whether this declaration is a function or function template. 901651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool isFunctionOrFunctionTemplate() const { 902651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return (DeclKind >= Decl::firstFunction && 903651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines DeclKind <= Decl::lastFunction) || 904651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines DeclKind == FunctionTemplate; 905651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 906651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 9074967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// \brief If this is a declaration that describes some template, this 9084967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// method returns that template declaration. 9094967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar TemplateDecl *getDescribedTemplate() const; 9104967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 911651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Returns the function itself, or the templated function if this is a 912651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// function template. 913651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines FunctionDecl *getAsFunction() LLVM_READONLY; 914651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 915651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const FunctionDecl *getAsFunction() const { 916651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return const_cast<Decl *>(this)->getAsFunction(); 917651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 91802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 91902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// \brief Changes the namespace of this declaration to reflect that it's 920a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// a function-local extern declaration. 921a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// 922a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// These declarations appear in the lexical context of the extern 923a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// declaration, but in the semantic context of the enclosing namespace 924a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// scope. 925a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith void setLocalExternDecl() { 926a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith assert((IdentifierNamespace == IDNS_Ordinary || 927a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IdentifierNamespace == IDNS_OrdinaryFriend) && 928a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith "namespace is not ordinary"); 929a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith 930a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith Decl *Prev = getPreviousDecl(); 931a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IdentifierNamespace &= ~IDNS_Ordinary; 932a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith 933a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IdentifierNamespace |= IDNS_LocalExtern; 934a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith if (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary) 935a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IdentifierNamespace |= IDNS_Ordinary; 936a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith } 937a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith 938a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// \brief Determine whether this is a block-scope declaration with linkage. 939a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// This will either be a local variable declaration declared 'extern', or a 940a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// local function declaration. 941a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith bool isLocalExternDecl() { 942a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith return IdentifierNamespace & IDNS_LocalExtern; 943a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith } 944a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith 945a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith /// \brief Changes the namespace of this declaration to reflect that it's 94602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// the object of a friend declaration. 94702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// 94802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// These declarations appear in the lexical context of the friending 94902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// class, but in the semantic context of the actual entity. This property 95002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// applies only to a specific decl object; other redeclarations of the 95102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// same entity may not (and probably don't) share this property. 95222050f25e34ba0cd21ee2dc3d765951c48e27cdeRichard Smith void setObjectOfFriendDecl(bool PerformFriendInjection = false) { 95302cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall unsigned OldNS = IdentifierNamespace; 954b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall assert((OldNS & (IDNS_Tag | IDNS_Ordinary | 955a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IDNS_TagFriend | IDNS_OrdinaryFriend | 956a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IDNS_LocalExtern)) && 957b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall "namespace includes neither ordinary nor tag"); 9580d6b1640eb4d1a4a0203235cfdfcdaf3335af36dJohn McCall assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | 959a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IDNS_TagFriend | IDNS_OrdinaryFriend | 960a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IDNS_LocalExtern)) && 961b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall "namespace includes other than ordinary or tag"); 962b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall 96322050f25e34ba0cd21ee2dc3d765951c48e27cdeRichard Smith Decl *Prev = getPreviousDecl(); 964a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith IdentifierNamespace &= ~(IDNS_Ordinary | IDNS_Tag | IDNS_Type); 965a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith 966b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall if (OldNS & (IDNS_Tag | IDNS_TagFriend)) { 96702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IdentifierNamespace |= IDNS_TagFriend; 968a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith if (PerformFriendInjection || 96922050f25e34ba0cd21ee2dc3d765951c48e27cdeRichard Smith (Prev && Prev->getIdentifierNamespace() & IDNS_Tag)) 97022050f25e34ba0cd21ee2dc3d765951c48e27cdeRichard Smith IdentifierNamespace |= IDNS_Tag | IDNS_Type; 971b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall } 972b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall 973a41c97a5d1912ffd184381d269fd8e5a25ee5e59Richard Smith if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend | IDNS_LocalExtern)) { 97402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall IdentifierNamespace |= IDNS_OrdinaryFriend; 97522050f25e34ba0cd21ee2dc3d765951c48e27cdeRichard Smith if (PerformFriendInjection || 97622050f25e34ba0cd21ee2dc3d765951c48e27cdeRichard Smith (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary)) 97722050f25e34ba0cd21ee2dc3d765951c48e27cdeRichard Smith IdentifierNamespace |= IDNS_Ordinary; 978b0cb022daec8671406ab25f4b5d5a6d48d823bc4John McCall } 97902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall } 98002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 98102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall enum FriendObjectKind { 9827841abf94eb8653b26aa8d5bf67f4ad0ff074767David Majnemer FOK_None, ///< Not a friend object. 9837841abf94eb8653b26aa8d5bf67f4ad0ff074767David Majnemer FOK_Declared, ///< A friend of a previously-declared entity. 9847841abf94eb8653b26aa8d5bf67f4ad0ff074767David Majnemer FOK_Undeclared ///< A friend of a previously-undeclared entity. 98502cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall }; 98602cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall 98702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// \brief Determines whether this declaration is the object of a 98802cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// friend declaration and, if so, what kind. 98902cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// 99002cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall /// There is currently no direct way to find the associated FriendDecl. 99102cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall FriendObjectKind getFriendObjectKind() const { 9922946cebdf49d3a6eeba8df93be291a07b2d58cbcDavid Majnemer unsigned mask = 9932946cebdf49d3a6eeba8df93be291a07b2d58cbcDavid Majnemer (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); 99402cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall if (!mask) return FOK_None; 9952946cebdf49d3a6eeba8df93be291a07b2d58cbcDavid Majnemer return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? FOK_Declared 9962946cebdf49d3a6eeba8df93be291a07b2d58cbcDavid Majnemer : FOK_Undeclared); 99702cace78cf48cc26686bd5b07c78606abca13bcdJohn McCall } 9981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99976d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall /// Specifies that this declaration is a C++ overloaded non-member. 100076d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall void setNonMemberOperator() { 100176d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall assert(getKind() == Function || getKind() == FunctionTemplate); 100276d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall assert((IdentifierNamespace & IDNS_Ordinary) && 100376d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall "visible non-member operators should be in ordinary namespace"); 100476d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall IdentifierNamespace |= IDNS_NonMemberOperator; 100576d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall } 100676d326448d7e4c10b2896edc2ee855d1e68d1b88John McCall 100780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static bool classofKind(Kind K) { return true; } 100842220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static DeclContext *castToDeclContext(const Decl *); 100942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static Decl *castFromDeclContext(const DeclContext *); 10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10115cb3d699f0e37de1767eb23d26d03953a46cf1ffRichard Trieu void print(raw_ostream &Out, unsigned Indentation = 0, 10125cb3d699f0e37de1767eb23d26d03953a46cf1ffRichard Trieu bool PrintInstantiation = false) const; 10138cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner void print(raw_ostream &Out, const PrintingPolicy &Policy, 10145cb3d699f0e37de1767eb23d26d03953a46cf1ffRichard Trieu unsigned Indentation = 0, bool PrintInstantiation = false) const; 101542f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman static void printGroup(Decl** Begin, unsigned NumDecls, 10168cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner raw_ostream &Out, const PrintingPolicy &Policy, 101742f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman unsigned Indentation = 0); 1018559b928b05aeacc9c984a9d633ad586bbe858196Alexander Kornienko // Debuggers don't usually respect default arguments. 1019651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void dump() const; 10207ba443aa8cfb222737d3a964a19ad4fb1328c4b5Richard Trieu // Same as dump(), but forces color printing. 1021651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void dumpColor() const; 1022559b928b05aeacc9c984a9d633ad586bbe858196Alexander Kornienko void dump(raw_ostream &Out) const; 10234fe0c8e9c76b96e7aff21696a40dacc09d0237bcDouglas Gregor 1024651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Looks through the Decl's underlying type to extract a FunctionType 1025651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// when possible. Will return null if the type underlying the Decl does not 1026651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// have a FunctionType. 1027651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const FunctionType *getFunctionType(bool BlocksToo = true) const; 1028651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 102981abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattnerprivate: 10304bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx); 10314bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC, 10324bbb8501d9db2ae72b1e39afaafa5795d67ffe03Argyrios Kyrtzidis ASTContext &Ctx); 103381abbdd848aa02c30242bd22dcc6ffe024ae2957Chris Lattner 10347b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidisprotected: 10357b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis ASTMutationListener *getASTMutationListener() const; 10360ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 10370ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1038eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor/// \brief Determine whether two declarations declare the same entity. 1039eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregorinline bool declaresSameEntity(const Decl *D1, const Decl *D2) { 1040eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor if (!D1 || !D2) 1041eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor return false; 1042eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor 1043dec1cc4ec73e96f315ab7dee51459700c0ad821dDouglas Gregor if (D1 == D2) 1044dec1cc4ec73e96f315ab7dee51459700c0ad821dDouglas Gregor return true; 1045dec1cc4ec73e96f315ab7dee51459700c0ad821dDouglas Gregor 1046eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor return D1->getCanonicalDecl() == D2->getCanonicalDecl(); 1047eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor} 1048eaa9511dd2bcb0c7f90f47a236a91c82048f484eDouglas Gregor 104949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when 105049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner/// doing something to a specific decl. 105149f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerclass PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { 1052c52365674b5b157a0486f75c12dd9f4cc41d8089Daniel Dunbar const Decl *TheDecl; 105349f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceLocation Loc; 105449f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &SM; 105549f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner const char *Message; 105649f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattnerpublic: 1057c52365674b5b157a0486f75c12dd9f4cc41d8089Daniel Dunbar PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, 105849f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner SourceManager &sm, const char *Msg) 105949f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} 10601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1061651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void print(raw_ostream &OS) const override; 10621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}; 10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10640e2c34f92f00628d48968dfea096d36381f494cbStephen Hines/// \brief The results of name lookup within a DeclContext. This is either a 10650e2c34f92f00628d48968dfea096d36381f494cbStephen Hines/// single result (with no stable storage) or a collection of results (with 10660e2c34f92f00628d48968dfea096d36381f494cbStephen Hines/// stable storage provided by the lookup table). 10670e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesclass DeclContextLookupResult { 10680e2c34f92f00628d48968dfea096d36381f494cbStephen Hines typedef ArrayRef<NamedDecl *> ResultTy; 10690e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ResultTy Result; 10700e2c34f92f00628d48968dfea096d36381f494cbStephen Hines // If there is only one lookup result, it would be invalidated by 10710e2c34f92f00628d48968dfea096d36381f494cbStephen Hines // reallocations of the name table, so store it separately. 10720e2c34f92f00628d48968dfea096d36381f494cbStephen Hines NamedDecl *Single; 1073ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall 10740e2c34f92f00628d48968dfea096d36381f494cbStephen Hines static NamedDecl *const SingleElementDummyList; 10750e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 10760e2c34f92f00628d48968dfea096d36381f494cbStephen Hinespublic: 10770e2c34f92f00628d48968dfea096d36381f494cbStephen Hines DeclContextLookupResult() : Result(), Single() {} 10780e2c34f92f00628d48968dfea096d36381f494cbStephen Hines DeclContextLookupResult(ArrayRef<NamedDecl *> Result) 10790e2c34f92f00628d48968dfea096d36381f494cbStephen Hines : Result(Result), Single() {} 10800e2c34f92f00628d48968dfea096d36381f494cbStephen Hines DeclContextLookupResult(NamedDecl *Single) 10810e2c34f92f00628d48968dfea096d36381f494cbStephen Hines : Result(SingleElementDummyList), Single(Single) {} 10820e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 10830e2c34f92f00628d48968dfea096d36381f494cbStephen Hines class iterator; 10840e2c34f92f00628d48968dfea096d36381f494cbStephen Hines typedef llvm::iterator_adaptor_base<iterator, ResultTy::iterator, 10850e2c34f92f00628d48968dfea096d36381f494cbStephen Hines std::random_access_iterator_tag, 10860e2c34f92f00628d48968dfea096d36381f494cbStephen Hines NamedDecl *const> IteratorBase; 10870e2c34f92f00628d48968dfea096d36381f494cbStephen Hines class iterator : public IteratorBase { 10880e2c34f92f00628d48968dfea096d36381f494cbStephen Hines value_type SingleElement; 10890e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 10900e2c34f92f00628d48968dfea096d36381f494cbStephen Hines public: 10910e2c34f92f00628d48968dfea096d36381f494cbStephen Hines iterator() : IteratorBase(), SingleElement() {} 10920e2c34f92f00628d48968dfea096d36381f494cbStephen Hines explicit iterator(pointer Pos, value_type Single = nullptr) 10930e2c34f92f00628d48968dfea096d36381f494cbStephen Hines : IteratorBase(Pos), SingleElement(Single) {} 10940e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 10950e2c34f92f00628d48968dfea096d36381f494cbStephen Hines reference operator*() const { 10960e2c34f92f00628d48968dfea096d36381f494cbStephen Hines return SingleElement ? SingleElement : IteratorBase::operator*(); 10970e2c34f92f00628d48968dfea096d36381f494cbStephen Hines } 10980e2c34f92f00628d48968dfea096d36381f494cbStephen Hines }; 10990e2c34f92f00628d48968dfea096d36381f494cbStephen Hines typedef iterator const_iterator; 11000e2c34f92f00628d48968dfea096d36381f494cbStephen Hines typedef iterator::pointer pointer; 11010e2c34f92f00628d48968dfea096d36381f494cbStephen Hines typedef iterator::reference reference; 11020e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 11030e2c34f92f00628d48968dfea096d36381f494cbStephen Hines iterator begin() const { return iterator(Result.begin(), Single); } 11040e2c34f92f00628d48968dfea096d36381f494cbStephen Hines iterator end() const { return iterator(Result.end(), Single); } 11050e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 11060e2c34f92f00628d48968dfea096d36381f494cbStephen Hines bool empty() const { return Result.empty(); } 11070e2c34f92f00628d48968dfea096d36381f494cbStephen Hines pointer data() const { return Single ? &Single : Result.data(); } 11080e2c34f92f00628d48968dfea096d36381f494cbStephen Hines size_t size() const { return Single ? 1 : Result.size(); } 11090e2c34f92f00628d48968dfea096d36381f494cbStephen Hines reference front() const { return Single ? Single : Result.front(); } 11100e2c34f92f00628d48968dfea096d36381f494cbStephen Hines reference back() const { return Single ? Single : Result.back(); } 11110e2c34f92f00628d48968dfea096d36381f494cbStephen Hines reference operator[](size_t N) const { return Single ? Single : Result[N]; } 11120e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 11130e2c34f92f00628d48968dfea096d36381f494cbStephen Hines // FIXME: Remove this from the interface 11140e2c34f92f00628d48968dfea096d36381f494cbStephen Hines DeclContextLookupResult slice(size_t N) const { 11150e2c34f92f00628d48968dfea096d36381f494cbStephen Hines DeclContextLookupResult Sliced = Result.slice(N); 11160e2c34f92f00628d48968dfea096d36381f494cbStephen Hines Sliced.Single = Single; 11170e2c34f92f00628d48968dfea096d36381f494cbStephen Hines return Sliced; 11180e2c34f92f00628d48968dfea096d36381f494cbStephen Hines } 11190e2c34f92f00628d48968dfea096d36381f494cbStephen Hines}; 112049f28ca787d8db7cac3c8898334f70ea55374c98Chris Lattner 1121b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner/// DeclContext - This is used only as base class of specific decl types that 11221ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// can act as declaration contexts. These decls are (only the top classes 11231ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// that directly derive from DeclContext are mentioned, not their subclasses): 11240ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// 1125ef177820100ab583b08fd3056e2a5a52ee4b1629Argyrios Kyrtzidis/// TranslationUnitDecl 11262d1c5d313cd0c229cc614e74baa4c5756a4b46f4Argyrios Kyrtzidis/// NamespaceDecl 11270ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner/// FunctionDecl 11281ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// TagDecl 1129d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8Argyrios Kyrtzidis/// ObjCMethodDecl 11301ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// ObjCContainerDecl 1131074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor/// LinkageSpecDecl 113256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockDecl 11334967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar/// OMPDeclareReductionDecl 11341ad4dd78ec53c24ea9e752b216035d7aa666fe49Argyrios Kyrtzidis/// 1135b048c9835969c4f7fe06264748be18ed4b442116Chris Lattnerclass DeclContext { 11360ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner /// DeclKind - This indicates which class this is. 113735043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall unsigned DeclKind : 8; 11380ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 11392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this declaration context also has some external 11402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// storage that contains additional declarations that are lexically 11412cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// part of this context. 1142bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith mutable bool ExternalLexicalStorage : 1; 11432cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 11442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this declaration context also has some external 11452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// storage that contains additional declarations that are visible 11462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// in this context. 1147bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith mutable bool ExternalVisibleStorage : 1; 1148bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith 1149bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// \brief Whether this declaration context has had external visible 1150bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// storage added since the last lookup. In this case, \c LookupPtr's 1151bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// invariant may not hold and needs to be fixed before we perform 1152bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith /// another lookup. 1153bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith mutable bool NeedToReconcileExternalVisibleStorage : 1; 11542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 11553ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// \brief If \c true, this context may have local lexical declarations 11563ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// that are missing from the lookup table. 11573ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar mutable bool HasLazyLocalLexicalLookups : 1; 11583ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 11593ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// \brief If \c true, the external source may have lexical declarations 11603ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// that are missing from the lookup table. 11613ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar mutable bool HasLazyExternalLexicalLookups : 1; 11623ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 116387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief If \c true, lookups should only return identifier from 116487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// DeclContext scope (for example TranslationUnit). Used in 116587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// LookupQualifiedName() 116687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar mutable bool UseQualifiedLookup : 1; 116787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 1168c36c540c5bfce941f3d892919394d092491211f2Douglas Gregor /// \brief Pointer to the data structure used to lookup declarations 11690c01d18094100db92d38daa923c95661512db203John McCall /// within this context (or a DependentStoredDeclsMap if this is a 11703ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// dependent context). We maintain the invariant that, if the map 11713ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// contains an entry for a DeclarationName (and we haven't lazily 11723ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// omitted anything), then it contains all relevant entries for that 11733ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// name (modulo the hasExternalDecls() flag). 11743ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar mutable StoredDeclsMap *LookupPtr; 117544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1176eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidisprotected: 11776037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// FirstDecl - The first declaration stored within this declaration 11786037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. 11792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable Decl *FirstDecl; 11806037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 11816037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// LastDecl - The last declaration stored within this declaration 11826037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// context. FIXME: We could probably cache this value somewhere 11836037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// outside of the DeclContext, to reduce the size of DeclContext by 11846037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// another pointer. 11852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor mutable Decl *LastDecl; 11867643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 118776bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall friend class ExternalASTSource; 1188e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith friend class ASTDeclReader; 1189643586fe4fcd42b0978efd3566832ab4dce50367Argyrios Kyrtzidis friend class ASTWriter; 119076bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall 1191eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis /// \brief Build up a chain of declarations. 1192eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis /// 1193eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis /// \returns the first/last pair of declarations. 1194eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis static std::pair<Decl *, Decl *> 1195341785ec52f87c0803ba52dc88faac4e136f8593Bill Wendling BuildDeclChain(ArrayRef<Decl*> Decls, bool FieldsAlreadyLoaded); 1196eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis 1197bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith DeclContext(Decl::Kind K) 1198bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith : DeclKind(K), ExternalLexicalStorage(false), 1199bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith ExternalVisibleStorage(false), 12003ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar NeedToReconcileExternalVisibleStorage(false), 12013ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar HasLazyLocalLexicalLookups(false), HasLazyExternalLexicalLookups(false), 120287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar UseQualifiedLookup(false), 12033ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar LookupPtr(nullptr), FirstDecl(nullptr), LastDecl(nullptr) {} 120444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 12050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnerpublic: 120644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ~DeclContext(); 120744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 12089b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis Decl::Kind getDeclKind() const { 120935043e56150dc4eda882acd5ddfe0f8e3c0a8cb1John McCall return static_cast<Decl::Kind>(DeclKind); 12109b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis } 12110a4739305a984ef9b821cedad5f4fe235eb6ef7dSteve Naroff const char *getDeclKindName() const; 12129b9ca01ff3136a7539dc08a4c4e1a3dd8c8d3a7dArgyrios Kyrtzidis 1213305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis /// getParent - Returns the containing DeclContext. 12140cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner DeclContext *getParent() { 1215305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis return cast<Decl>(this)->getDeclContext(); 1216305ec42f971a2b3e114eb35256c23e955c497a1cArgyrios Kyrtzidis } 12170cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getParent() const { 12180cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<DeclContext*>(this)->getParent(); 1219d2595ecce5f8350e485c83bfe767549a522b2802Argyrios Kyrtzidis } 12201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 122177407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// getLexicalParent - Returns the containing lexical DeclContext. May be 122244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// different from getParent, e.g.: 122344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// 122444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace A { 122544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct S; 122644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 122744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// struct A::S {}; // getParent() == namespace 'A' 122877407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// // getLexicalParent() == translation unit 122977407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis /// 123077407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis DeclContext *getLexicalParent() { 12310cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return cast<Decl>(this)->getLexicalDeclContext(); 123277407b802130b1c44b1f63b855722a5376f57bcaArgyrios Kyrtzidis } 12330cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner const DeclContext *getLexicalParent() const { 12340cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return const_cast<DeclContext*>(this)->getLexicalParent(); 12351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1236048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis 1237e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor DeclContext *getLookupParent(); 1238ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1239e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor const DeclContext *getLookupParent() const { 1240e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor return const_cast<DeclContext*>(this)->getLookupParent(); 1241e942bbe02b6fb332d1f13d38c6e1980b416cf89aDouglas Gregor } 1242ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1243048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis ASTContext &getParentASTContext() const { 1244048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis return cast<Decl>(this)->getASTContext(); 1245048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis } 1246048f30a483ca352ee7f235a5be181b9dcc5f9d9cArgyrios Kyrtzidis 1247aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall bool isClosure() const { 1248aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall return DeclKind == Decl::Block; 1249aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall } 1250aab9e315184d344bbd733f13b68915d02db7b32bJohn McCall 1251a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian bool isObjCContainer() const { 125280f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian switch (DeclKind) { 125380f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCCategory: 125480f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCCategoryImpl: 125580f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCImplementation: 125680f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCInterface: 125780f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian case Decl::ObjCProtocol: 125880f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian return true; 125980f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian } 126080f775359357f90f34b6adb8104506f13a816a67Fariborz Jahanian return false; 1261a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian } 1262a28948f34817476d02412fa204cae038e228c827Fariborz Jahanian 12630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner bool isFunctionOrMethod() const { 12640ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner switch (DeclKind) { 12650cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner case Decl::Block: 12666afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj case Decl::Captured: 12670cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner case Decl::ObjCMethod: 12680cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner return true; 12690cf2b1990c82121d03a004dafe498ba43bf4b42aChris Lattner default: 12709a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction; 12710ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 12720ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 12730ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 12743ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// \brief Test whether the context supports looking up names. 12753ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar bool isLookupContext() const { 12763ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar return !isFunctionOrMethod() && DeclKind != Decl::LinkageSpec; 12773ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar } 12783ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 1279ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis bool isFileContext() const { 1280ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 1281ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis } 1282ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 12835f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor bool isTranslationUnit() const { 12845f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor return DeclKind == Decl::TranslationUnit; 12855f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor } 12865f2bfd4811996abb783aa6c7254c56baa6930e8cDouglas Gregor 1287bcbffc46f1ad3796c4582fa1e3a9113b5aa26061Douglas Gregor bool isRecord() const { 12889a55591af3e5506b95a9718e15380129fbfc5ebcSean Hunt return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord; 1289c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis } 1290c7ed9c60b8ee04b119e23441cae2cfec74536ba9Argyrios Kyrtzidis 129144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor bool isNamespace() const { 129244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return DeclKind == Decl::Namespace; 129344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 129444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 12956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool isStdNamespace() const; 12966bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1297410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl bool isInlineNamespace() const; 1298410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl 1299bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor /// \brief Determines whether this context is dependent on a 1300bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor /// template parameter. 1301bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor bool isDependentContext() const; 1302bc221637f5ed3538b8495dd13b831c11e821c712Douglas Gregor 1303074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// isTransparentContext - Determines whether this context is a 1304074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// "transparent" context, meaning that the members declared in this 1305074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// context are semantically declared in the nearest enclosing 1306074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// non-transparent (opaque) context but are lexically declared in 1307074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// this context. For example, consider the enumerators of an 13081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// enumeration type: 1309074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @code 1310074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// enum E { 13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Val1 1312074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// }; 1313074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// @endcode 1314074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Here, E is a transparent context, so its enumerator (Val1) will 1315074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// appear (semantically) that it is in the same context of E. 1316074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor /// Examples of transparent contexts include: enumerations (except for 1317410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl /// C++0x scoped enums), and C++ linkage specifications. 1318074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor bool isTransparentContext() const; 1319074149e11baf5f7db12f84efd5c34ba6e35d5cdfDouglas Gregor 1320142ab06ffb2ec286917554aa5d945323a1ebf359Serge Pavlov /// \brief Determines whether this context or some of its ancestors is a 1321142ab06ffb2ec286917554aa5d945323a1ebf359Serge Pavlov /// linkage specification context that specifies C linkage. 1322142ab06ffb2ec286917554aa5d945323a1ebf359Serge Pavlov bool isExternCContext() const; 1323142ab06ffb2ec286917554aa5d945323a1ebf359Serge Pavlov 1324142ab06ffb2ec286917554aa5d945323a1ebf359Serge Pavlov /// \brief Determines whether this context or some of its ancestors is a 1325142ab06ffb2ec286917554aa5d945323a1ebf359Serge Pavlov /// linkage specification context that specifies C++ linkage. 1326142ab06ffb2ec286917554aa5d945323a1ebf359Serge Pavlov bool isExternCXXContext() const; 1327142ab06ffb2ec286917554aa5d945323a1ebf359Serge Pavlov 132861481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor /// \brief Determine whether this declaration context is equivalent 132961481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor /// to the declaration context DC. 13307a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl bool Equals(const DeclContext *DC) const { 1331dbdf5e7d0b6f1f8d8c496c1a0ada6f706cddf100Douglas Gregor return DC && this->getPrimaryContext() == DC->getPrimaryContext(); 133261481dad22ebca3fba3fe4fb67a3b926d0895e9cDouglas Gregor } 13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13346dd38daf1495367db8fe9e9a5cacb7420cf08e27Douglas Gregor /// \brief Determine whether this declaration context encloses the 13356dd38daf1495367db8fe9e9a5cacb7420cf08e27Douglas Gregor /// declaration context DC. 13367a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl bool Encloses(const DeclContext *DC) const; 1337ef6e647b8d3268a765c2c4dd7f8a73cad281a8e6Argyrios Kyrtzidis 13384b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// \brief Find the nearest non-closure ancestor of this context, 13394b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// i.e. the innermost semantic parent of this context which is not 13404b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// a closure. A context may be its own non-closure ancestor. 1341f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall Decl *getNonClosureAncestor(); 1342f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall const Decl *getNonClosureAncestor() const { 13434b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<DeclContext*>(this)->getNonClosureAncestor(); 13444b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 13454b9c2d235fb9449e249d74f48ecfec601650de93John McCall 134644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// getPrimaryContext - There may be many different 134744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// declarations of the same entity (including forward declarations 134844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// of classes, multiple definitions of namespaces, etc.), each with 134944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// a different set of declarations. This routine returns the 135044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// "primary" DeclContext structure, which will contain the 135144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// information needed to perform name lookup into this context. 13520701bbb228dfd87e1fe82a0a4b7b9facfecb43daSteve Naroff DeclContext *getPrimaryContext(); 13530c01d18094100db92d38daa923c95661512db203John McCall const DeclContext *getPrimaryContext() const { 13540c01d18094100db92d38daa923c95661512db203John McCall return const_cast<DeclContext*>(this)->getPrimaryContext(); 13550c01d18094100db92d38daa923c95661512db203John McCall } 135644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 13577a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// getRedeclContext - Retrieve the context in which an entity conflicts with 13587a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// other entities of the same name, or where it is a redeclaration if the 1359410c4f2eb5e6a8c2318cacb9a6751f1b4fcff166Sebastian Redl /// two entities are compatible. This skips through transparent contexts. 13607a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl DeclContext *getRedeclContext(); 13617a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl const DeclContext *getRedeclContext() const { 13627a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl return const_cast<DeclContext *>(this)->getRedeclContext(); 136317a9b9e3ee75f5dbb4819cc8ebf40eec8015f84aDouglas Gregor } 13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136588b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor /// \brief Retrieve the nearest enclosing namespace context. 136688b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor DeclContext *getEnclosingNamespaceContext(); 136788b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor const DeclContext *getEnclosingNamespaceContext() const { 136888b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); 136988b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor } 137088b7094185b9d4fe9820c731b6936d8d37f6143eDouglas Gregor 1371176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \brief Retrieve the outermost lexically enclosing record context. 1372176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines RecordDecl *getOuterLexicalRecordContext(); 1373176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const RecordDecl *getOuterLexicalRecordContext() const { 1374176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return const_cast<DeclContext *>(this)->getOuterLexicalRecordContext(); 1375176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 1376176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 13777a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// \brief Test if this context is part of the enclosing namespace set of 13787a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// the context NS, as defined in C++0x [namespace.def]p9. If either context 13797a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// isn't a namespace, this is equivalent to Equals(). 13807a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// 13817a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// The enclosing namespace set of a namespace is the namespace and, if it is 13827a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl /// inline, its enclosing namespace, recursively. 13837a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl bool InEnclosingNamespaceSetOf(const DeclContext *NS) const; 13847a126a474fdde06382b315b4e3d8ef0a21d4dc31Sebastian Redl 138518483f583333f8d940393e64ce111c6979639665James Dennett /// \brief Collects all of the declaration contexts that are semantically 1386f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// connected to this declaration context. 1387f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// 1388f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// For declaration contexts that have multiple semantically connected but 1389f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// syntactically distinct contexts, such as C++ namespaces, this routine 1390f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// retrieves the complete set of such declaration contexts in source order. 1391f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// For example, given: 1392f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// 1393f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// \code 139444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 139544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int x; 139644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 139744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// namespace N { 139844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// int y; 139944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// } 1400f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// \endcode 1401f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// 1402f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// The \c Contexts parameter will contain both definitions of N. 1403f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// 1404f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// \param Contexts Will be cleared and set to the set of declaration 1405f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// contexts that are semanticaly connected to this declaration context, 1406f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// in source order, including this context (which may be the only result, 1407f5c9f9fd6f5e2850b9b0f19283430245b696c6e5Douglas Gregor /// for non-namespace contexts). 1408cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko void collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts); 140944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 141044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decl_iterator - Iterates through the declarations stored 141144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// within this context. 14126037fcba3431b47de1a994c9b286feac17894effDouglas Gregor class decl_iterator { 14136037fcba3431b47de1a994c9b286feac17894effDouglas Gregor /// Current - The current declaration. 14144afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor Decl *Current; 14156037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 14166037fcba3431b47de1a994c9b286feac17894effDouglas Gregor public: 1417581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef Decl *value_type; 1418581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef const value_type &reference; 1419581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef const value_type *pointer; 14206037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::forward_iterator_tag iterator_category; 14216037fcba3431b47de1a994c9b286feac17894effDouglas Gregor typedef std::ptrdiff_t difference_type; 14226037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 14236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines decl_iterator() : Current(nullptr) { } 14244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor explicit decl_iterator(Decl *C) : Current(C) { } 14256037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 14266037fcba3431b47de1a994c9b286feac17894effDouglas Gregor reference operator*() const { return Current; } 1427581deb3da481053c4993c7600f97acf7768caac5David Blaikie // This doesn't meet the iterator requirements, but it's convenient 1428581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator->() const { return Current; } 14296037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 143096f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner decl_iterator& operator++() { 1431244a67d911d08c3757a18ad666e4a268cf3ee285Chris Lattner Current = Current->getNextDeclInContext(); 143296f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner return *this; 143396f4468b6b1bf69bb01c1207f716a3ffaeb4a8d3Chris Lattner } 14346037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 14356037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator operator++(int) { 14366037fcba3431b47de1a994c9b286feac17894effDouglas Gregor decl_iterator tmp(*this); 14376037fcba3431b47de1a994c9b286feac17894effDouglas Gregor ++(*this); 14386037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return tmp; 14396037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 14406037fcba3431b47de1a994c9b286feac17894effDouglas Gregor 14411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator==(decl_iterator x, decl_iterator y) { 14426037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current == y.Current; 14436037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump friend bool operator!=(decl_iterator x, decl_iterator y) { 14456037fcba3431b47de1a994c9b286feac17894effDouglas Gregor return x.Current != y.Current; 14466037fcba3431b47de1a994c9b286feac17894effDouglas Gregor } 14476037fcba3431b47de1a994c9b286feac17894effDouglas Gregor }; 144844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1449651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<decl_iterator> decl_range; 1450651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 145144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// decls_begin/decls_end - Iterate over the declarations stored in 14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// this context. 1453651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines decl_range decls() const { return decl_range(decls_begin(), decls_end()); } 145417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis decl_iterator decls_begin() const; 1455581deb3da481053c4993c7600f97acf7768caac5David Blaikie decl_iterator decls_end() const { return decl_iterator(); } 145617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis bool decls_empty() const; 145744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1458681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl /// noload_decls_begin/end - Iterate over the declarations stored in this 1459681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl /// context that are currently loaded; don't attempt to retrieve anything 1460681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl /// from an external source. 1461651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines decl_range noload_decls() const { 1462651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return decl_range(noload_decls_begin(), noload_decls_end()); 1463651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 1464651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines decl_iterator noload_decls_begin() const { return decl_iterator(FirstDecl); } 1465581deb3da481053c4993c7600f97acf7768caac5David Blaikie decl_iterator noload_decls_end() const { return decl_iterator(); } 1466681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl 1467f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Iterates over a subrange of 1468f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declarations stored in a DeclContext, providing only those that 1469669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// are of type SpecificDecl (or a class derived from it). This 1470f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// iterator is used, for example, to provide iteration over just 1471669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). 1472f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor template<typename SpecificDecl> 1473f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor class specific_decl_iterator { 1474f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// Current - The current, underlying declaration iterator, which 1475d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// will either be NULL or will point to a declaration of 1476f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// type SpecificDecl. 1477f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor DeclContext::decl_iterator Current; 14781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1479f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 1480f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 1481f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// required by Acceptable. 1482f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor void SkipToNextDecl() { 1483669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && !isa<SpecificDecl>(*Current)) 1484f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 1485f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1486f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1487f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor public: 1488581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef SpecificDecl *value_type; 1489581deb3da481053c4993c7600f97acf7768caac5David Blaikie // TODO: Add reference and pointer typedefs (with some appropriate proxy 1490581deb3da481053c4993c7600f97acf7768caac5David Blaikie // type) if we ever have a need for them. 1491581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef void reference; 1492581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef void pointer; 1493f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 1494f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor difference_type; 1495f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor typedef std::forward_iterator_tag iterator_category; 1496f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1497669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor specific_decl_iterator() : Current() { } 1498f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1499f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor /// specific_decl_iterator - Construct a new iterator over a 1500d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// subset of the declarations the range [C, 1501d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 1502d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// member function of SpecificDecl that should return true for 1503d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// all of the SpecificDecl instances that will be in the subset 1504d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// of iterators. For example, if you want Objective-C instance 1505d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 1506d6f0b4e97e681ea5d165125960f34b3b8c19e1dcDouglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 1507669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 1508f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 1509f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1510f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1511581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator*() const { return cast<SpecificDecl>(*Current); } 1512581deb3da481053c4993c7600f97acf7768caac5David Blaikie // This doesn't meet the iterator requirements, but it's convenient 1513581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator->() const { return **this; } 1514f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1515f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator& operator++() { 1516f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++Current; 1517f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor SkipToNextDecl(); 1518f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return *this; 1519f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1520f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1521f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator operator++(int) { 1522f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor specific_decl_iterator tmp(*this); 1523f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor ++(*this); 1524f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return tmp; 1525f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1527ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie friend bool operator==(const specific_decl_iterator& x, 1528ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const specific_decl_iterator& y) { 1529f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current == y.Current; 1530f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1532ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie friend bool operator!=(const specific_decl_iterator& x, 1533ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const specific_decl_iterator& y) { 1534f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor return x.Current != y.Current; 1535f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor } 1536f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor }; 1537f8d49f64ef6ab7e632717a31631fc289aab69428Douglas Gregor 1538669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// \brief Iterates over a filtered subrange of declarations stored 1539669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// in a DeclContext. 1540669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// 1541669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// This iterator visits only those declarations that are of type 1542669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SpecificDecl (or a class derived from it) and that meet some 1543669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// additional run-time criteria. This iterator is used, for 1544669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// example, to provide access to the instance methods within an 1545669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and 1546669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Acceptable = ObjCMethodDecl::isInstanceMethod). 1547669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> 1548669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor class filtered_decl_iterator { 1549669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// Current - The current, underlying declaration iterator, which 1550669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// will either be NULL or will point to a declaration of 1551669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// type SpecificDecl. 1552669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor DeclContext::decl_iterator Current; 15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1554669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// SkipToNextDecl - Advances the current position up to the next 1555669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// declaration of type SpecificDecl that also meets the criteria 1556669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// required by Acceptable. 1557669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor void SkipToNextDecl() { 1558669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor while (*Current && 1559669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (!isa<SpecificDecl>(*Current) || 1560669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 1561669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 1562669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1563669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1564669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor public: 1565581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef SpecificDecl *value_type; 1566581deb3da481053c4993c7600f97acf7768caac5David Blaikie // TODO: Add reference and pointer typedefs (with some appropriate proxy 1567581deb3da481053c4993c7600f97acf7768caac5David Blaikie // type) if we ever have a need for them. 1568581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef void reference; 1569581deb3da481053c4993c7600f97acf7768caac5David Blaikie typedef void pointer; 1570669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 1571669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor difference_type; 1572669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor typedef std::forward_iterator_tag iterator_category; 1573669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1574669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator() : Current() { } 1575669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1576bd4fa45e7cf6a2f0adcb0ab66d5b3d338ec56c3cDavid Blaikie /// filtered_decl_iterator - Construct a new iterator over a 1577669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// subset of the declarations the range [C, 1578669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// end-of-declarations). If A is non-NULL, it is a pointer to a 1579669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// member function of SpecificDecl that should return true for 1580669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// all of the SpecificDecl instances that will be in the subset 1581669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// of iterators. For example, if you want Objective-C instance 1582669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// methods, SpecificDecl will be ObjCMethodDecl and A will be 1583669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor /// &ObjCMethodDecl::isInstanceMethod. 1584669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 1585669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 1586669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1587669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1588581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator*() const { return cast<SpecificDecl>(*Current); } 1589581deb3da481053c4993c7600f97acf7768caac5David Blaikie value_type operator->() const { return cast<SpecificDecl>(*Current); } 1590669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1591669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator& operator++() { 1592669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++Current; 1593669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor SkipToNextDecl(); 1594669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return *this; 1595669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1596669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 1597669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator operator++(int) { 1598669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor filtered_decl_iterator tmp(*this); 1599669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor ++(*this); 1600669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return tmp; 1601669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1603ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie friend bool operator==(const filtered_decl_iterator& x, 1604ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const filtered_decl_iterator& y) { 1605669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current == y.Current; 1606669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1608ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie friend bool operator!=(const filtered_decl_iterator& x, 1609ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie const filtered_decl_iterator& y) { 1610669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor return x.Current != y.Current; 1611669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor } 1612669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor }; 1613669c9a28fa4be35e6b6322aa7f2f3b2968189b80Douglas Gregor 161440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Add the declaration D into this context. 161540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 161640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine should be invoked when the declaration D has first 161740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// been declared, to place D into the context where it was 161840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (lexically) defined. Every declaration must be added to one 161940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// (and only one!) context, where it can be visited via 162040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// [decls_begin(), decls_end()). Once a declaration has been added 162140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// to its lexical context, the corresponding DeclContext owns the 162240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration. 162340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 162440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is also a NamedDecl, it will be made visible within its 162540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// semantic context via makeDeclVisibleInContext. 162617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis void addDecl(Decl *D); 1627381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan 1628381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// @brief Add the declaration D into this context, but suppress 1629381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// searches for external declarations with the same name. 1630381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// 1631381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// Although analogous in function to addDecl, this removes an 1632381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// important check. This is only useful if the Decl is being 1633381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// added in response to an external search; in all other cases, 1634381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// addDecl() is the right function to use. 1635381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// See the ASTImporter for use cases. 16369faf810f08132aabb34a478297dfeea89c3bbe17Sean Callanan void addDeclInternal(Decl *D); 163744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 16383f9a8a60614b763785d54ad08821745d03a4af70John McCall /// @brief Add the declaration D to this context without modifying 16393f9a8a60614b763785d54ad08821745d03a4af70John McCall /// any lookup tables. 16403f9a8a60614b763785d54ad08821745d03a4af70John McCall /// 16413f9a8a60614b763785d54ad08821745d03a4af70John McCall /// This is useful for some operations in dependent contexts where 16423f9a8a60614b763785d54ad08821745d03a4af70John McCall /// the semantic context might not be dependent; this basically 16433f9a8a60614b763785d54ad08821745d03a4af70John McCall /// only happens with friends. 16443f9a8a60614b763785d54ad08821745d03a4af70John McCall void addHiddenDecl(Decl *D); 16453f9a8a60614b763785d54ad08821745d03a4af70John McCall 16469f54ad4381370c6b771424b53d219e661d6d6706John McCall /// @brief Removes a declaration from this context. 16479f54ad4381370c6b771424b53d219e661d6d6706John McCall void removeDecl(Decl *D); 1648cd904e8864637e427f5ea3bf35a26e79b3dbbadfSean Callanan 1649cd904e8864637e427f5ea3bf35a26e79b3dbbadfSean Callanan /// @brief Checks whether a declaration is in this context. 1650cd904e8864637e427f5ea3bf35a26e79b3dbbadfSean Callanan bool containsDecl(Decl *D) const; 16519f54ad4381370c6b771424b53d219e661d6d6706John McCall 1652ea318642072d3d94b5c3cff0fa6f4b33d2db0768John McCall typedef DeclContextLookupResult lookup_result; 16530e2c34f92f00628d48968dfea096d36381f494cbStephen Hines typedef lookup_result::iterator lookup_iterator; 165444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 165544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// lookup - Find the declarations (if any) with the given Name in 165644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor /// this context. Returns a range of iterators that contains all of 165740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// the declarations with this name, with object, function, member, 165840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// and enumerator names preceding any tag name. Note that this 165940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// routine will not look into parent contexts. 16600e2c34f92f00628d48968dfea096d36381f494cbStephen Hines lookup_result lookup(DeclarationName Name) const; 166144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 1662e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith /// \brief Find the declarations with the given name that are visible 1663e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith /// within this context; don't attempt to retrieve anything from an 1664e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith /// external source. 1665e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith lookup_result noload_lookup(DeclarationName Name); 1666e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith 1667b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// \brief A simplistic name lookup mechanism that performs name lookup 1668b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// into this declaration context without consulting the external source. 1669b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// 1670ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// This function should almost never be used, because it subverts the 1671b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// usual relationship between a DeclContext and the external source. 1672b75a3451bcae1301875282e73a13934c90b6574cDouglas Gregor /// See the ASTImporter for the (few, but important) use cases. 1673e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith /// 1674e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith /// FIXME: This is very inefficient; replace uses of it with uses of 1675e7bae1597f4a7088f5048695c14a8f1013a86108Richard Smith /// noload_lookup. 1676ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void localUncachedLookup(DeclarationName Name, 1677cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVectorImpl<NamedDecl *> &Results); 1678ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 167940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// @brief Makes a declaration visible within this context. 168040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 168140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// This routine makes the declaration D visible to name lookup 168240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within this context and, if this is a transparent context, 168340f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// within its parent contexts up to the first enclosing 168440f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// non-transparent context. Making a declaration visible within a 168540f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// context does not transfer ownership of a declaration, and a 168640f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// declaration can be visible in many contexts that aren't its 168740f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// lexical context. 168840f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// 168940f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// If D is a redeclaration of an existing declaration that is 169040f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// visible from this context, as determined by 169140f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// NamedDecl::declarationReplaces, the previous declaration will be 169240f4e69002af9623a1f959bd57b99afda186a6a7Douglas Gregor /// replaced with D. 16931b7f9cbed1b96b58a6e5f7808ebc9345a76a0936Richard Smith void makeDeclVisibleInContext(NamedDecl *D); 16947643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 1695173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky /// all_lookups_iterator - An iterator that provides a view over the results 1696173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky /// of looking up every possible name. 1697173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky class all_lookups_iterator; 1698173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky 1699651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<all_lookups_iterator> lookups_range; 1700651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1701651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines lookups_range lookups() const; 1702651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines lookups_range noload_lookups() const; 1703651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 17046e322c08b187ba93019732d2295c84c339813e0dRichard Smith /// \brief Iterators over all possible lookups within this context. 1705173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky all_lookups_iterator lookups_begin() const; 1706173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky all_lookups_iterator lookups_end() const; 1707173a37a57b79bd8f94b85c2273039e760b159922Nick Lewycky 17086e322c08b187ba93019732d2295c84c339813e0dRichard Smith /// \brief Iterators over all possible lookups within this context that are 17096e322c08b187ba93019732d2295c84c339813e0dRichard Smith /// currently loaded; don't attempt to retrieve anything from an external 17106e322c08b187ba93019732d2295c84c339813e0dRichard Smith /// source. 17116e322c08b187ba93019732d2295c84c339813e0dRichard Smith all_lookups_iterator noload_lookups_begin() const; 17126e322c08b187ba93019732d2295c84c339813e0dRichard Smith all_lookups_iterator noload_lookups_end() const; 17136e322c08b187ba93019732d2295c84c339813e0dRichard Smith 17140e2c34f92f00628d48968dfea096d36381f494cbStephen Hines struct udir_iterator; 17150e2c34f92f00628d48968dfea096d36381f494cbStephen Hines typedef llvm::iterator_adaptor_base<udir_iterator, lookup_iterator, 17160e2c34f92f00628d48968dfea096d36381f494cbStephen Hines std::random_access_iterator_tag, 17170e2c34f92f00628d48968dfea096d36381f494cbStephen Hines UsingDirectiveDecl *> udir_iterator_base; 17180e2c34f92f00628d48968dfea096d36381f494cbStephen Hines struct udir_iterator : udir_iterator_base { 17190e2c34f92f00628d48968dfea096d36381f494cbStephen Hines udir_iterator(lookup_iterator I) : udir_iterator_base(I) {} 17200e2c34f92f00628d48968dfea096d36381f494cbStephen Hines UsingDirectiveDecl *operator*() const; 17210e2c34f92f00628d48968dfea096d36381f494cbStephen Hines }; 17220e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 17230e2c34f92f00628d48968dfea096d36381f494cbStephen Hines typedef llvm::iterator_range<udir_iterator> udir_range; 17242a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 1725651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines udir_range using_directives() const; 17262a3009a432bdcec59e6383d7b2b17494d6f91649Douglas Gregor 17270c01d18094100db92d38daa923c95661512db203John McCall // These are all defined in DependentDiagnostic.h. 17280c01d18094100db92d38daa923c95661512db203John McCall class ddiag_iterator; 1729651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines typedef llvm::iterator_range<DeclContext::ddiag_iterator> ddiag_range; 1730651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1731651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines inline ddiag_range ddiags() const; 17320c01d18094100db92d38daa923c95661512db203John McCall 1733c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor // Low-level accessors 17343ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 17353ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// \brief Mark that there are external lexical declarations that we need 17363ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// to include in our lookup table (and that are not available as external 17373ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// visible lookups). These extra lookup results will be found by walking 17383ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// the lexical declarations of this context. This should be used only if 17393ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// setHasExternalLexicalStorage() has been called on any decl context for 17403ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar /// which this is the primary context. 1741d5a20c19416d7143771b4d503fa808ae01c4e7adSean Callanan void setMustBuildLookupTable() { 17423ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar assert(this == getPrimaryContext() && 17433ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar "should only be called on primary context"); 17443ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar HasLazyExternalLexicalLookups = true; 1745d5a20c19416d7143771b4d503fa808ae01c4e7adSean Callanan } 1746c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 1747c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor /// \brief Retrieve the internal representation of the lookup structure. 1748c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith /// This may omit some names if we are lazily building the structure. 17493ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar StoredDeclsMap *getLookupPtr() const { return LookupPtr; } 1750c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith 1751c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith /// \brief Ensure the lookup structure is fully-built and return it. 1752c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith StoredDeclsMap *buildLookup(); 1753c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 17542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this DeclContext has external storage containing 17552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// additional declarations that are lexically in this context. 17562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; } 17572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 17582cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief State whether this DeclContext has external storage for 17592cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// declarations lexically in this context. 17601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setHasExternalLexicalStorage(bool ES = true) { 17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalLexicalStorage = ES; 17622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 17632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 17642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief Whether this DeclContext has external storage containing 17652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// additional declarations that are visible in this context. 17662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; } 17672cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 17682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// \brief State whether this DeclContext has external storage for 17692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor /// declarations visible in this context. 17701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setHasExternalVisibleStorage(bool ES = true) { 17711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExternalVisibleStorage = ES; 17723ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar if (ES && LookupPtr) 1773bbcd0f3ba215d5a8857b224e32b0330586a00dc6Richard Smith NeedToReconcileExternalVisibleStorage = true; 17742cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 17752cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 17762ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor /// \brief Determine whether the given declaration is stored in the list of 17772ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor /// declarations lexically within this context. 17782ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor bool isDeclInLexicalTraversal(const Decl *D) const { 177946cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor return D && (D->NextInContextAndBits.getPointer() || D == FirstDecl || 178046cd2186bddc3e046140cb2d56932ee7faf7e3aeDouglas Gregor D == LastDecl); 17812ea054fbc59ed19b8e3304e7e7cbdd56a5a5120fDouglas Gregor } 1782ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 178387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool setUseQualifiedLookup(bool use = true) { 178487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool old_value = UseQualifiedLookup; 178587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar UseQualifiedLookup = use; 178687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return old_value; 178787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 178887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 178987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar bool shouldUseQualifiedLookup() const { 179087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return UseQualifiedLookup; 179187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 179287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 17933d7641e090cf113dec64306a1597d3e4523e2a55Argyrios Kyrtzidis static bool classof(const Decl *D); 1794b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static bool classof(const DeclContext *D) { return true; } 17957643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidis 1796651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void dumpDeclContext() const; 1797651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void dumpLookups() const; 1798176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines void dumpLookups(llvm::raw_ostream &OS, bool DumpDecls = false) const; 17992b7d8ddc746a9096f8af4bd0d8b07eae523864b5Anders Carlsson 18007643536c36b0449256d5ee2efc03a7e4a784a0b3Argyrios Kyrtzidisprivate: 1801651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void reconcileExternalVisibleStorage() const; 18023ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar bool LoadLexicalDeclsFromExternalStorage() const; 1803ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1804ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// @brief Makes a declaration visible within this context, but 1805381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// suppresses searches for external declarations with the same 1806381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// name. 1807381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// 1808381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// Analogous to makeDeclVisibleInContext, but for the exclusive 1809381509ea9965ab6bde9b36b4131ad08bf851d9b4Sean Callanan /// use of addDeclInternal(). 18101b7f9cbed1b96b58a6e5f7808ebc9345a76a0936Richard Smith void makeDeclVisibleInContextInternal(NamedDecl *D); 18112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 18120c01d18094100db92d38daa923c95661512db203John McCall friend class DependentDiagnostic; 18130c01d18094100db92d38daa923c95661512db203John McCall StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const; 18140c01d18094100db92d38daa923c95661512db203John McCall 18150e2c34f92f00628d48968dfea096d36381f494cbStephen Hines void buildLookupImpl(DeclContext *DCtx, bool Internal); 1816c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith void makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal, 1817c5d3e80c64af9604ad798282cc6861f9cd2afc52Richard Smith bool Rediscoverable); 18189faf810f08132aabb34a478297dfeea89c3bbe17Sean Callanan void makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal); 18190ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 18200ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 1821f57172b24f08a68d179675989813d5479dc87829Douglas Gregorinline bool Decl::isTemplateParameter() const { 182279c2278a66d8fc0943774d1b7c71a32f7764e1e2Douglas Gregor return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm || 182379c2278a66d8fc0943774d1b7c71a32f7764e1e2Douglas Gregor getKind() == TemplateTemplateParm; 18244afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor} 18254afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor 182680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall// Specialization selected when ToTy is not a known subclass of DeclContext. 182780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate <class ToTy, 1828651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool IsKnownSubtype = ::std::is_base_of<DeclContext, ToTy>::value> 182980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_decl_context { 183080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy *doit(const DeclContext *Val) { 183180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<const ToTy*>(Decl::castFromDeclContext(Val)); 183280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 183380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 183480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy *doit(DeclContext *Val) { 183580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<ToTy*>(Decl::castFromDeclContext(Val)); 183680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 183780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 183880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 183980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall// Specialization selected when ToTy is a known subclass of DeclContext. 184080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate <class ToTy> 184180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_decl_context<ToTy, true> { 184280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy *doit(const DeclContext *Val) { 184380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<const ToTy*>(Val); 184480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 184580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 184680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy *doit(DeclContext *Val) { 184780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return static_cast<ToTy*>(Val); 184880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 184980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 185080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 185180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 18520ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end clang. 18530ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 18540ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnernamespace llvm { 18550ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 185680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall/// isa<T>(DeclContext*) 18574d509341bd5db06a517daa311379f52bb540bc34Eli Friedmantemplate <typename To> 18584d509341bd5db06a517daa311379f52bb540bc34Eli Friedmanstruct isa_impl<To, ::clang::DeclContext> { 185942220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis static bool doit(const ::clang::DeclContext &Val) { 18604d509341bd5db06a517daa311379f52bb540bc34Eli Friedman return To::classofKind(Val.getDeclKind()); 18610ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 18620ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 18630ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 186480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall/// cast<T>(DeclContext*) 186580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 186680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, 186780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall const ::clang::DeclContext,const ::clang::DeclContext> { 186880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy &doit(const ::clang::DeclContext &Val) { 186980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 187080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 187180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 187280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 187380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> { 187480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy &doit(::clang::DeclContext &Val) { 187580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 187680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 187780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 187880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 187980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, 188080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall const ::clang::DeclContext*, const ::clang::DeclContext*> { 188180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static const ToTy *doit(const ::clang::DeclContext *Val) { 188280cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 188380cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 188480cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 188580cd64a8450d8e2c079dc134d9711cd45ba89d63John McCalltemplate<class ToTy> 188680cd64a8450d8e2c079dc134d9711cd45ba89d63John McCallstruct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> { 188780cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall static ToTy *doit(::clang::DeclContext *Val) { 188880cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 188980cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall } 189080cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall}; 189180cd64a8450d8e2c079dc134d9711cd45ba89d63John McCall 189242220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis/// Implement cast_convert_val for Decl -> DeclContext conversions. 18930ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 189442220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 1895b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext &doit(const FromTy &Val) { 189642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return *FromTy::castToDeclContext(&Val); 18970ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 18980ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 18990ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 19000ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattnertemplate<class FromTy> 190142220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidisstruct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 1902b048c9835969c4f7fe06264748be18ed4b442116Chris Lattner static ::clang::DeclContext *doit(const FromTy *Val) { 190342220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis return FromTy::castToDeclContext(Val); 19040ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner } 19050ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner}; 190642220c5432c141d47cc8ce786e472b49dc907378Argyrios Kyrtzidis 190744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 190844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 190944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext &doit(const FromTy &Val) { 191044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return *FromTy::castToDeclContext(&Val); 191144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 191244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 191344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 191444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregortemplate<class FromTy> 191544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregorstruct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 191644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor static const ::clang::DeclContext *doit(const FromTy *Val) { 191744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return FromTy::castToDeclContext(Val); 191844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 191944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor}; 192044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 19210ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner} // end namespace llvm 19220ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner 19230ed844b04ea4387caa4e1cf3dc375d269657536bChris Lattner#endif 1924