DeclBase.h revision d4582b8e6d056f5d991f1b8372e89a6aae58feae
14b6829f0d28990dd645e16386eb226d0f10c8731shiqian//===-- DeclBase.h - Base Classes for representing declarations -*- C++ -*-===// 24b6829f0d28990dd645e16386eb226d0f10c8731shiqian// 34b6829f0d28990dd645e16386eb226d0f10c8731shiqian// The LLVM Compiler Infrastructure 44b6829f0d28990dd645e16386eb226d0f10c8731shiqian// 54b6829f0d28990dd645e16386eb226d0f10c8731shiqian// This file is distributed under the University of Illinois Open Source 64b6829f0d28990dd645e16386eb226d0f10c8731shiqian// License. See LICENSE.TXT for details. 74b6829f0d28990dd645e16386eb226d0f10c8731shiqian// 84b6829f0d28990dd645e16386eb226d0f10c8731shiqian//===----------------------------------------------------------------------===// 94b6829f0d28990dd645e16386eb226d0f10c8731shiqian// 104b6829f0d28990dd645e16386eb226d0f10c8731shiqian// This file defines the Decl and DeclContext interfaces. 114b6829f0d28990dd645e16386eb226d0f10c8731shiqian// 124b6829f0d28990dd645e16386eb226d0f10c8731shiqian//===----------------------------------------------------------------------===// 134b6829f0d28990dd645e16386eb226d0f10c8731shiqian 144b6829f0d28990dd645e16386eb226d0f10c8731shiqian#ifndef LLVM_CLANG_AST_DECLBASE_H 154b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define LLVM_CLANG_AST_DECLBASE_H 164b6829f0d28990dd645e16386eb226d0f10c8731shiqian 174b6829f0d28990dd645e16386eb226d0f10c8731shiqian#include "clang/AST/AttrIterator.h" 184b6829f0d28990dd645e16386eb226d0f10c8731shiqian#include "clang/AST/DeclarationName.h" 194b6829f0d28990dd645e16386eb226d0f10c8731shiqian#include "clang/Basic/Specifiers.h" 204b6829f0d28990dd645e16386eb226d0f10c8731shiqian#include "llvm/ADT/PointerUnion.h" 214b6829f0d28990dd645e16386eb226d0f10c8731shiqian#include "llvm/Support/Compiler.h" 224b6829f0d28990dd645e16386eb226d0f10c8731shiqian#include "llvm/Support/PrettyStackTrace.h" 234b6829f0d28990dd645e16386eb226d0f10c8731shiqian 244b6829f0d28990dd645e16386eb226d0f10c8731shiqiannamespace clang { 254b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass ASTMutationListener; 264b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass BlockDecl; 274b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass CXXRecordDecl; 284b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass CompoundStmt; 294b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass DeclContext; 304b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass DeclarationName; 314b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass DependentDiagnostic; 324b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass EnumDecl; 334b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass FunctionDecl; 342620c79810d4741922e9fa89050c0af564994f24zhanyong.wanclass LinkageSpecDecl; 352620c79810d4741922e9fa89050c0af564994f24zhanyong.wanclass Module; 362620c79810d4741922e9fa89050c0af564994f24zhanyong.wanclass NamedDecl; 374b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass NamespaceDecl; 38f6d087b78d230d875bf5d8281112662795044680zhanyong.wanclass ObjCCategoryDecl; 39f6d087b78d230d875bf5d8281112662795044680zhanyong.wanclass ObjCCategoryImplDecl; 40f6d087b78d230d875bf5d8281112662795044680zhanyong.wanclass ObjCContainerDecl; 414cd62602913a032a7aec091d4c8055ff9af95e37zhanyong.wanclass ObjCImplDecl; 424b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass ObjCImplementationDecl; 43733a54a398766289b74cf3daebe083d7115cf388zhanyong.wanclass ObjCInterfaceDecl; 44733a54a398766289b74cf3daebe083d7115cf388zhanyong.wanclass ObjCMethodDecl; 45733a54a398766289b74cf3daebe083d7115cf388zhanyong.wanclass ObjCProtocolDecl; 46733a54a398766289b74cf3daebe083d7115cf388zhanyong.wanstruct PrintingPolicy; 47733a54a398766289b74cf3daebe083d7115cf388zhanyong.wanclass Stmt; 48733a54a398766289b74cf3daebe083d7115cf388zhanyong.wanclass StoredDeclsMap; 49c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wanclass TranslationUnitDecl; 50733a54a398766289b74cf3daebe083d7115cf388zhanyong.wanclass UsingDirectiveDecl; 51733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan} 52733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 53dd617c1bc8e67a915068e8462881fbc5e2f6ae30zhanyong.wannamespace llvm { 547c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev// DeclContext* is only 4-byte aligned on 32-bit systems. 557c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosevtemplate<> 567c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev class PointerLikeTypeTraits<clang::DeclContext*> { 577c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev typedef clang::DeclContext* PT; 58733a54a398766289b74cf3daebe083d7115cf388zhanyong.wanpublic: 594b6829f0d28990dd645e16386eb226d0f10c8731shiqian static inline void *getAsVoidPointer(PT P) { return P; } 604b6829f0d28990dd645e16386eb226d0f10c8731shiqian static inline PT getFromVoidPointer(void *P) { 614b6829f0d28990dd645e16386eb226d0f10c8731shiqian return static_cast<PT>(P); 624b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 634b6829f0d28990dd645e16386eb226d0f10c8731shiqian enum { NumLowBitsAvailable = 2 }; 644b6829f0d28990dd645e16386eb226d0f10c8731shiqian}; 65733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan} 66733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 67733a54a398766289b74cf3daebe083d7115cf388zhanyong.wannamespace clang { 684b6829f0d28990dd645e16386eb226d0f10c8731shiqian 69a49bf25b24dd239a9da88e783f037d817a6287b0zhanyong.wan /// \brief Captures the result of checking the availability of a 70c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// declaration. 71a49bf25b24dd239a9da88e783f037d817a6287b0zhanyong.wan enum AvailabilityResult { 724b6829f0d28990dd645e16386eb226d0f10c8731shiqian AR_Available = 0, 734b6829f0d28990dd645e16386eb226d0f10c8731shiqian AR_NotYetIntroduced, 74baa766af2a71363fb1ccf8de5de444c4a88f0e61zhanyong.wan AR_Deprecated, 75b0b40063a828ca7a4ceb079ecd508775c6aa9d93zhanyong.wan AR_Unavailable 76a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan }; 77f46f3eaf059b7b3ca00a3428c594bd477bc1839cvladlosev 78c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan/// Decl - This represents one declaration (or definition), e.g. a variable, 794b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// typedef, function, struct, etc. 804b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// 814b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass Decl { 824b6829f0d28990dd645e16386eb226d0f10c8731shiqianpublic: 834b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Lists the kind of concrete classes of Decl. 844b6829f0d28990dd645e16386eb226d0f10c8731shiqian enum Kind { 854b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define DECL(DERIVED, BASE) DERIVED, 864b6829f0d28990dd645e16386eb226d0f10c8731shiqian#define ABSTRACT_DECL(DECL) 87a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan#define DECL_RANGE(BASE, START, END) \ 88a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan first##BASE = START, last##BASE = END, 89a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan#define LAST_DECL_RANGE(BASE, START, END) \ 90a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan first##BASE = START, last##BASE = END 914b6829f0d28990dd645e16386eb226d0f10c8731shiqian#include "clang/AST/DeclNodes.inc" 924b6829f0d28990dd645e16386eb226d0f10c8731shiqian }; 934b6829f0d28990dd645e16386eb226d0f10c8731shiqian 94a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan /// \brief A placeholder type used to construct an empty shell of a 95a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan /// decl-derived type that will be filled in later (e.g., by some 964b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// deserialization method). 974b6829f0d28990dd645e16386eb226d0f10c8731shiqian struct EmptyShell { }; 984b6829f0d28990dd645e16386eb226d0f10c8731shiqian 994b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// IdentifierNamespace - The different namespaces in which 1004b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// declarations may appear. According to C99 6.2.3, there are 1014b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// four namespaces, labels, tags, members and ordinary 102a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan /// identifiers. C++ describes lookup completely differently: 1034b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// certain lookups merely "ignore" certain kinds of declarations, 1044b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// usually based on whether the declaration is of a type, etc. 1054b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 1064b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// These are meant as bitmasks, so that searches in 1074b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// C++ can look into the "tag" namespace during ordinary lookup. 1084b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 10934b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// Decl currently provides 15 bits of IDNS bits. 11034b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan enum IdentifierNamespace { 11134b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// Labels, declared with 'x:' and referenced with 'goto x'. 11234b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan IDNS_Label = 0x0001, 113b1fc4d36385c457e2237e778859759219f1604b6vladlosev 114b1fc4d36385c457e2237e778859759219f1604b6vladlosev /// Tags, declared with 'struct foo;' and referenced with 115b1fc4d36385c457e2237e778859759219f1604b6vladlosev /// 'struct foo'. All tags are also types. This is what 116b1fc4d36385c457e2237e778859759219f1604b6vladlosev /// elaborated-type-specifiers look for in C. 1170a4157359e39ecd69e143e4410099eadfb320f75vladlosev IDNS_Tag = 0x0002, 1180a4157359e39ecd69e143e4410099eadfb320f75vladlosev 1190a4157359e39ecd69e143e4410099eadfb320f75vladlosev /// Types, declared with 'struct foo', typedefs, etc. 1200a4157359e39ecd69e143e4410099eadfb320f75vladlosev /// This is what elaborated-type-specifiers look for in C++, 1210a4157359e39ecd69e143e4410099eadfb320f75vladlosev /// but note that it's ill-formed to find a non-tag. 1220a4157359e39ecd69e143e4410099eadfb320f75vladlosev IDNS_Type = 0x0004, 123b1fc4d36385c457e2237e778859759219f1604b6vladlosev 124b1fc4d36385c457e2237e778859759219f1604b6vladlosev /// Members, declared with object declarations within tag 12534b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// definitions. In C, these can only be found by "qualified" 12634b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// lookup in member expressions. In C++, they're found by 12734b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// normal lookup. 12834b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan IDNS_Member = 0x0008, 1294b6829f0d28990dd645e16386eb226d0f10c8731shiqian 1304b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// Namespaces, declared with 'namespace foo {}'. 1314b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// Lookup for nested-name-specifiers find these. 1324b6829f0d28990dd645e16386eb226d0f10c8731shiqian IDNS_Namespace = 0x0010, 133baa766af2a71363fb1ccf8de5de444c4a88f0e61zhanyong.wan 134baa766af2a71363fb1ccf8de5de444c4a88f0e61zhanyong.wan /// Ordinary names. In C, everything that's not a label, tag, 135baa766af2a71363fb1ccf8de5de444c4a88f0e61zhanyong.wan /// or member ends up here. 136c7f60f1514013d57a624c3a2966709998678f24bzhanyong.wan IDNS_Ordinary = 0x0020, 137baa766af2a71363fb1ccf8de5de444c4a88f0e61zhanyong.wan 138baa766af2a71363fb1ccf8de5de444c4a88f0e61zhanyong.wan /// Objective C \@protocol. 1394b6829f0d28990dd645e16386eb226d0f10c8731shiqian IDNS_ObjCProtocol = 0x0040, 140b1fc4d36385c457e2237e778859759219f1604b6vladlosev 1414b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// This declaration is a friend function. A friend function 1424b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// declaration is always in this namespace but may also be in 1434b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// IDNS_Ordinary if it was previously declared. 144b1fc4d36385c457e2237e778859759219f1604b6vladlosev IDNS_OrdinaryFriend = 0x0080, 145b1fc4d36385c457e2237e778859759219f1604b6vladlosev 1464b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// This declaration is a friend class. A friend class 1474b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// declaration is always in this namespace but may also be in 1484b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// IDNS_Tag|IDNS_Type if it was previously declared. 1494b6829f0d28990dd645e16386eb226d0f10c8731shiqian IDNS_TagFriend = 0x0100, 150baa766af2a71363fb1ccf8de5de444c4a88f0e61zhanyong.wan 1514b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// This declaration is a using declaration. A using declaration 1524b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// *introduces* a number of other declarations into the current 1534b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// scope, and those declarations use the IDNS of their targets, 1544b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// but the actual using declarations go in this namespace. 1554b6829f0d28990dd645e16386eb226d0f10c8731shiqian IDNS_Using = 0x0200, 1564b6829f0d28990dd645e16386eb226d0f10c8731shiqian 1574b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// This declaration is a C++ operator declared in a non-class 1584b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// context. All such operators are also in IDNS_Ordinary. 1594b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// C++ lexical operator lookup looks for these. 160b1fc4d36385c457e2237e778859759219f1604b6vladlosev IDNS_NonMemberOperator = 0x0400 161b1fc4d36385c457e2237e778859759219f1604b6vladlosev }; 1624b6829f0d28990dd645e16386eb226d0f10c8731shiqian 1634b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// ObjCDeclQualifier - 'Qualifiers' written next to the return and 1644b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// parameter types in method declarations. Other than remembering 1654b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// them and mangling them into the method's signature string, these 1664b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// are ignored by the compiler; they are consumed by certain 1674b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// remote-messaging frameworks. 1684b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 1694b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// in, inout, and out are mutually exclusive and apply only to 170b1fc4d36385c457e2237e778859759219f1604b6vladlosev /// method parameters. bycopy and byref are mutually exclusive and 1714b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// apply only to method parameters (?). oneway applies only to 1724b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// results. All of these expect their corresponding parameter to 1734b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// have a particular type. None of this is currently enforced by 174b1fc4d36385c457e2237e778859759219f1604b6vladlosev /// clang. 1754b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 1764b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// This should be kept in sync with ObjCDeclSpec::ObjCDeclQualifier. 1774b6829f0d28990dd645e16386eb226d0f10c8731shiqian enum ObjCDeclQualifier { 1784b6829f0d28990dd645e16386eb226d0f10c8731shiqian OBJC_TQ_None = 0x0, 1794b6829f0d28990dd645e16386eb226d0f10c8731shiqian OBJC_TQ_In = 0x1, 180b1fc4d36385c457e2237e778859759219f1604b6vladlosev OBJC_TQ_Inout = 0x2, 181b1fc4d36385c457e2237e778859759219f1604b6vladlosev OBJC_TQ_Out = 0x4, 1824b6829f0d28990dd645e16386eb226d0f10c8731shiqian OBJC_TQ_Bycopy = 0x8, 1834b6829f0d28990dd645e16386eb226d0f10c8731shiqian OBJC_TQ_Byref = 0x10, 1844b6829f0d28990dd645e16386eb226d0f10c8731shiqian OBJC_TQ_Oneway = 0x20 1854b6829f0d28990dd645e16386eb226d0f10c8731shiqian }; 1864b6829f0d28990dd645e16386eb226d0f10c8731shiqian 187b1fc4d36385c457e2237e778859759219f1604b6vladlosevprotected: 1884b6829f0d28990dd645e16386eb226d0f10c8731shiqian // Enumeration values used in the bits stored in NextInContextAndBits. 1894b6829f0d28990dd645e16386eb226d0f10c8731shiqian enum { 1904b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration is a top-level declaration (function, 1914b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// global variable, etc.) that is lexically inside an objc container 1924b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// definition. 1934b6829f0d28990dd645e16386eb226d0f10c8731shiqian TopLevelDeclInObjCContainerFlag = 0x01, 1944b6829f0d28990dd645e16386eb226d0f10c8731shiqian 1954b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration is private to the module in which it was 1964b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// defined. 1974b6829f0d28990dd645e16386eb226d0f10c8731shiqian ModulePrivateFlag = 0x02 1984b6829f0d28990dd645e16386eb226d0f10c8731shiqian }; 1994b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2004b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief The next declaration within the same lexical 201733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// DeclContext. These pointers form the linked list that is 202733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// traversed via DeclContext's decls_begin()/decls_end(). 203733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// 204b1fc4d36385c457e2237e778859759219f1604b6vladlosev /// The extra two bits are used for the TopLevelDeclInObjCContainer and 205733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// ModulePrivate bits. 206733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan llvm::PointerIntPair<Decl *, 2, unsigned> NextInContextAndBits; 207733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 2084b6829f0d28990dd645e16386eb226d0f10c8731shiqianprivate: 2094b6829f0d28990dd645e16386eb226d0f10c8731shiqian friend class DeclContext; 2104b6829f0d28990dd645e16386eb226d0f10c8731shiqian 211733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan struct MultipleDC { 212c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan DeclContext *SemanticDC; 213c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan DeclContext *LexicalDC; 214c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan }; 215c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 216c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 217c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. 218c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// For declarations that don't contain C++ scope specifiers, it contains 219c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// the DeclContext where the Decl was declared. 220c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// For declarations with C++ scope specifiers, it contains a MultipleDC* 221c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// with the context where it semantically belongs (SemanticDC) and the 222c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// context where it was lexically declared (LexicalDC). 223c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// e.g.: 224733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// 225c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// namespace A { 226c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian /// void f(); // SemanticDC == LexicalDC == 'namespace A' 2274b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// } 2284b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// void A::f(); // SemanticDC == namespace 'A' 2294b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// // LexicalDC == global namespace 2304b6829f0d28990dd645e16386eb226d0f10c8731shiqian llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; 2314b6829f0d28990dd645e16386eb226d0f10c8731shiqian 232c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } 2334b6829f0d28990dd645e16386eb226d0f10c8731shiqian inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } 2344b6829f0d28990dd645e16386eb226d0f10c8731shiqian inline MultipleDC *getMultipleDC() const { 2354b6829f0d28990dd645e16386eb226d0f10c8731shiqian return DeclCtx.get<MultipleDC*>(); 2364b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 2374b6829f0d28990dd645e16386eb226d0f10c8731shiqian inline DeclContext *getSemanticDC() const { 2384b6829f0d28990dd645e16386eb226d0f10c8731shiqian return DeclCtx.get<DeclContext*>(); 2394b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 2404b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2414b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// Loc - The location of this decl. 2424b6829f0d28990dd645e16386eb226d0f10c8731shiqian SourceLocation Loc; 2434b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2444b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// DeclKind - This indicates which class this is. 2454b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned DeclKind : 8; 2464b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2474b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// InvalidDecl - This indicates a semantic error occurred. 248c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian unsigned InvalidDecl : 1; 2494b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2504b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// HasAttrs - This indicates whether the decl has attributes or not. 2514b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned HasAttrs : 1; 2524b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2534b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// Implicit - Whether this declaration was implicitly generated by 2544b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// the implementation rather than explicitly written by the user. 2554b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned Implicit : 1; 2564b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2574b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration was "used", meaning that a definition is 2584b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// required. 2594b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned Used : 1; 2604b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2614b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration was "referenced". 2624b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// The difference with 'Used' is whether the reference appears in a 2634b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// evaluated context or not, e.g. functions used in uninstantiated templates 2644b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// are regarded as "referenced" but not "used". 2654b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned Referenced : 1; 2664b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2674b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether statistic collection is enabled. 2684b6829f0d28990dd645e16386eb226d0f10c8731shiqian static bool StatisticsEnabled; 2694b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2704b6829f0d28990dd645e16386eb226d0f10c8731shiqianprotected: 2714b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// Access - Used by C++ decls for the access specifier. 2724b6829f0d28990dd645e16386eb226d0f10c8731shiqian // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 2734b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned Access : 2; 2744b6829f0d28990dd645e16386eb226d0f10c8731shiqian friend class CXXClassMemberWrapper; 2754b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2764b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration was loaded from an AST file. 2774b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned FromASTFile : 1; 2784b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2794b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration is hidden from normal name lookup, e.g., 2804b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// because it is was loaded from an AST file is either module-private or 2814b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// because its submodule has not been made visible. 2824b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned Hidden : 1; 283733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 284c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. 2854b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned IdentifierNamespace : 12; 2864b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2874b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether the \c CachedLinkage field is active. 2884b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 289f6d087b78d230d875bf5d8281112662795044680zhanyong.wan /// This field is only valid for NamedDecls subclasses. 2904b6829f0d28990dd645e16386eb226d0f10c8731shiqian mutable unsigned HasCachedLinkage : 1; 2914b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2924b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief If \c HasCachedLinkage, the linkage of this declaration. 293f6d087b78d230d875bf5d8281112662795044680zhanyong.wan /// 294c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian /// This field is only valid for NamedDecls subclasses. 2954b6829f0d28990dd645e16386eb226d0f10c8731shiqian mutable unsigned CachedLinkage : 2; 2964b6829f0d28990dd645e16386eb226d0f10c8731shiqian 2974b6829f0d28990dd645e16386eb226d0f10c8731shiqian friend class ASTDeclWriter; 2984b6829f0d28990dd645e16386eb226d0f10c8731shiqian friend class ASTDeclReader; 2994b6829f0d28990dd645e16386eb226d0f10c8731shiqian friend class ASTReader; 300f6d087b78d230d875bf5d8281112662795044680zhanyong.wan 3014b6829f0d28990dd645e16386eb226d0f10c8731shiqianprivate: 3024b6829f0d28990dd645e16386eb226d0f10c8731shiqian void CheckAccessDeclContext() const; 303f6d087b78d230d875bf5d8281112662795044680zhanyong.wan 3044b6829f0d28990dd645e16386eb226d0f10c8731shiqianprotected: 3054b6829f0d28990dd645e16386eb226d0f10c8731shiqian 306c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian Decl(Kind DK, DeclContext *DC, SourceLocation L) 3074b6829f0d28990dd645e16386eb226d0f10c8731shiqian : NextInContextAndBits(), DeclCtx(DC), 3084b6829f0d28990dd645e16386eb226d0f10c8731shiqian Loc(L), DeclKind(DK), InvalidDecl(0), 3094b6829f0d28990dd645e16386eb226d0f10c8731shiqian HasAttrs(false), Implicit(false), Used(false), Referenced(false), 31089be5763249cbab785abfa310fb1cd6b5e9c4adfzhanyong.wan Access(AS_none), FromASTFile(0), Hidden(0), 311c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 312c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian HasCachedLinkage(0) 3134b6829f0d28990dd645e16386eb226d0f10c8731shiqian { 3144b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (StatisticsEnabled) add(DK); 315733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan } 3164b6829f0d28990dd645e16386eb226d0f10c8731shiqian 3174b6829f0d28990dd645e16386eb226d0f10c8731shiqian Decl(Kind DK, EmptyShell Empty) 318dd617c1bc8e67a915068e8462881fbc5e2f6ae30zhanyong.wan : NextInContextAndBits(), DeclKind(DK), InvalidDecl(0), 3194b6829f0d28990dd645e16386eb226d0f10c8731shiqian HasAttrs(false), Implicit(false), Used(false), Referenced(false), 3204b6829f0d28990dd645e16386eb226d0f10c8731shiqian Access(AS_none), FromASTFile(0), Hidden(0), 32189be5763249cbab785abfa310fb1cd6b5e9c4adfzhanyong.wan IdentifierNamespace(getIdentifierNamespaceForKind(DK)), 32289be5763249cbab785abfa310fb1cd6b5e9c4adfzhanyong.wan HasCachedLinkage(0) 3234b6829f0d28990dd645e16386eb226d0f10c8731shiqian { 324733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan if (StatisticsEnabled) add(DK); 3254b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 3264b6829f0d28990dd645e16386eb226d0f10c8731shiqian 3274b6829f0d28990dd645e16386eb226d0f10c8731shiqian virtual ~Decl(); 3284b6829f0d28990dd645e16386eb226d0f10c8731shiqian 329f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// \brief Allocate memory for a deserialized declaration. 330f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// 331f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// This routine must be used to allocate memory for any declaration that is 332c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// deserialized from a module file. 3334b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 3344b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \param Context The context in which we will allocate memory. 335c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian /// \param ID The global ID of the deserialized declaration. 3364b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \param Size The size of the allocated object. 3374b6829f0d28990dd645e16386eb226d0f10c8731shiqian static void *AllocateDeserializedDecl(const ASTContext &Context, 3384b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned ID, 339c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian unsigned Size); 340c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 341f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// \brief Update a potentially out-of-date declaration. 3424b6829f0d28990dd645e16386eb226d0f10c8731shiqian void updateOutOfDate(IdentifierInfo &II) const; 3434b6829f0d28990dd645e16386eb226d0f10c8731shiqian 344c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqianpublic: 345c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian 346c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian /// \brief Source range that this declaration covers. 347c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian virtual SourceRange getSourceRange() const LLVM_READONLY { 3484b6829f0d28990dd645e16386eb226d0f10c8731shiqian return SourceRange(getLocation(), getLocation()); 3494b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 3504b6829f0d28990dd645e16386eb226d0f10c8731shiqian SourceLocation getLocStart() const LLVM_READONLY { 351c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian return getSourceRange().getBegin(); 352c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian } 353c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian SourceLocation getLocEnd() const LLVM_READONLY { 354c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian return getSourceRange().getEnd(); 3554b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 3564b6829f0d28990dd645e16386eb226d0f10c8731shiqian 3574b6829f0d28990dd645e16386eb226d0f10c8731shiqian SourceLocation getLocation() const { return Loc; } 3584b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setLocation(SourceLocation L) { Loc = L; } 359c7f60f1514013d57a624c3a2966709998678f24bzhanyong.wan 360c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan Kind getKind() const { return static_cast<Kind>(DeclKind); } 361c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian const char *getDeclKindName() const; 362c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian 363c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian Decl *getNextDeclInContext() { return NextInContextAndBits.getPointer(); } 364c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian const Decl *getNextDeclInContext() const {return NextInContextAndBits.getPointer();} 365c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian 366c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan DeclContext *getDeclContext() { 367c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian if (isInSemaDC()) 368c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian return getSemanticDC(); 369c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan return getMultipleDC()->SemanticDC; 370c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian } 371c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian const DeclContext *getDeclContext() const { 372c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian return const_cast<Decl*>(this)->getDeclContext(); 3737c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev } 3747c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 3757c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev /// Finds the innermost non-closure context of this declaration. 3767c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev /// That is, walk out the DeclContext chain, skipping any blocks. 3777c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev DeclContext *getNonClosureContext(); 3787c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev const DeclContext *getNonClosureContext() const { 3797c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev return const_cast<Decl*>(this)->getNonClosureContext(); 3807c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev } 3817c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 3827c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev TranslationUnitDecl *getTranslationUnitDecl(); 3837c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev const TranslationUnitDecl *getTranslationUnitDecl() const { 3847c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev return const_cast<Decl*>(this)->getTranslationUnitDecl(); 3857c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev } 3867c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 3877c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev bool isInAnonymousNamespace() const; 3887c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 3897c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev ASTContext &getASTContext() const LLVM_READONLY; 3907c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 3917c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev void setAccess(AccessSpecifier AS) { 3927c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev Access = AS; 3937c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev#ifndef NDEBUG 3945f4d53c8ef453c82f87095711dd072370d496c0bvladlosev CheckAccessDeclContext(); 3957c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev#endif 3965f4d53c8ef453c82f87095711dd072370d496c0bvladlosev } 3977c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 3987c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev AccessSpecifier getAccess() const { 3997c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev#ifndef NDEBUG 4007c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev CheckAccessDeclContext(); 4017c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev#endif 4027c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev return AccessSpecifier(Access); 4037c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev } 4047c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 4057c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev bool hasAttrs() const { return HasAttrs; } 4067c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev void setAttrs(const AttrVec& Attrs) { 4077c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev return setAttrsImpl(Attrs, getASTContext()); 4087c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev } 4097c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev AttrVec &getAttrs() { 4107c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs()); 4117c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev } 4127c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev const AttrVec &getAttrs() const; 4137c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev void swapAttrs(Decl *D); 4147c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev void dropAttrs(); 4157c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 4167c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev void addAttr(Attr *A) { 4177c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev if (hasAttrs()) 4187c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev getAttrs().push_back(A); 4197c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev else 4207c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev setAttrs(AttrVec(1, A)); 4217c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev } 4227c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 4237c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev typedef AttrVec::const_iterator attr_iterator; 4247c3004c3013fe4adf5e0447d37ee2d0501c2b227vladlosev 4254b6829f0d28990dd645e16386eb226d0f10c8731shiqian // FIXME: Do not rely on iterators having comparable singular values. 4264b6829f0d28990dd645e16386eb226d0f10c8731shiqian // Note that this should error out if they do not. 4274b6829f0d28990dd645e16386eb226d0f10c8731shiqian attr_iterator attr_begin() const { 4284b6829f0d28990dd645e16386eb226d0f10c8731shiqian return hasAttrs() ? getAttrs().begin() : 0; 4294b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 4304b6829f0d28990dd645e16386eb226d0f10c8731shiqian attr_iterator attr_end() const { 4314b6829f0d28990dd645e16386eb226d0f10c8731shiqian return hasAttrs() ? getAttrs().end() : 0; 4324b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 4334b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4344b6829f0d28990dd645e16386eb226d0f10c8731shiqian template <typename T> 4354b6829f0d28990dd645e16386eb226d0f10c8731shiqian void dropAttr() { 4364b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (!HasAttrs) return; 4374b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4384b6829f0d28990dd645e16386eb226d0f10c8731shiqian AttrVec &Vec = getAttrs(); 4394b6829f0d28990dd645e16386eb226d0f10c8731shiqian Vec.erase(std::remove_if(Vec.begin(), Vec.end(), isa<T, Attr*>), Vec.end()); 4404b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4414b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (Vec.empty()) 442c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian HasAttrs = false; 443c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian } 444c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian 445c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian template <typename T> 446c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian specific_attr_iterator<T> specific_attr_begin() const { 447c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian return specific_attr_iterator<T>(attr_begin()); 448c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan } 449c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian template <typename T> 450c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian specific_attr_iterator<T> specific_attr_end() const { 451c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan return specific_attr_iterator<T>(attr_end()); 452c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian } 4534b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4544b6829f0d28990dd645e16386eb226d0f10c8731shiqian template<typename T> T *getAttr() const { 4554b6829f0d28990dd645e16386eb226d0f10c8731shiqian return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : 0; 4564b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 457c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian template<typename T> bool hasAttr() const { 4584b6829f0d28990dd645e16386eb226d0f10c8731shiqian return hasAttrs() && hasSpecificAttr<T>(getAttrs()); 459c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian } 4604b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4614b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// getMaxAlignment - return the maximum alignment specified by attributes 46274de57c951aedebc5dfe26a27604353432392b98zhanyong.wan /// on this decl, 0 if there are none. 46374de57c951aedebc5dfe26a27604353432392b98zhanyong.wan unsigned getMaxAlignment() const; 4644b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4654b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// setInvalidDecl - Indicates the Decl had a semantic error. This 4664b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// allows for graceful error recovery. 4674b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setInvalidDecl(bool Invalid = true); 4684b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isInvalidDecl() const { return (bool) InvalidDecl; } 4694b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4704b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// isImplicit - Indicates whether the declaration was implicitly 4714b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// generated by the implementation. If false, this declaration 4724b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// was written explicitly in the source code. 4734b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isImplicit() const { return Implicit; } 4744b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setImplicit(bool I = true) { Implicit = I; } 47521d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian 47621d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian /// \brief Whether this declaration was used, meaning that a definition 47721d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian /// is required. 47821d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian /// 47921d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian /// \param CheckUsedAttr When true, also consider the "used" attribute 48021d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian /// (in addition to the "used" bit set by \c setUsed()) when determining 48121d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian /// whether the function is used. 4824b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isUsed(bool CheckUsedAttr = true) const; 4834b6829f0d28990dd645e16386eb226d0f10c8731shiqian 484733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan void setUsed(bool U = true) { Used = U; } 485c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 4864b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration was referenced. 4874b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isReferenced() const; 4884b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4894b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setReferenced(bool R = true) { Referenced = R; } 4904b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4914b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration is a top-level declaration (function, 4924b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// global variable, etc.) that is lexically inside an objc container 4934b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// definition. 4944b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isTopLevelDeclInObjCContainer() const { 4954b6829f0d28990dd645e16386eb226d0f10c8731shiqian return NextInContextAndBits.getInt() & TopLevelDeclInObjCContainerFlag; 4964b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 4974b6829f0d28990dd645e16386eb226d0f10c8731shiqian 4984b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setTopLevelDeclInObjCContainer(bool V = true) { 4994b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned Bits = NextInContextAndBits.getInt(); 5004b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (V) 5014b6829f0d28990dd645e16386eb226d0f10c8731shiqian Bits |= TopLevelDeclInObjCContainerFlag; 5024b6829f0d28990dd645e16386eb226d0f10c8731shiqian else 5034b6829f0d28990dd645e16386eb226d0f10c8731shiqian Bits &= ~TopLevelDeclInObjCContainerFlag; 5044b6829f0d28990dd645e16386eb226d0f10c8731shiqian NextInContextAndBits.setInt(Bits); 5054b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 506733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 507733a54a398766289b74cf3daebe083d7115cf388zhanyong.wanprotected: 5084b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration was marked as being private to the 5094b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// module in which it was defined. 510733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan bool isModulePrivate() const { 511733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan return NextInContextAndBits.getInt() & ModulePrivateFlag; 5124b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 5134b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5144b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Specify whether this declaration was marked as being private 5154b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// to the module in which it was defined. 5164b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setModulePrivate(bool MP = true) { 5174b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned Bits = NextInContextAndBits.getInt(); 5184b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (MP) 5194b6829f0d28990dd645e16386eb226d0f10c8731shiqian Bits |= ModulePrivateFlag; 5204b6829f0d28990dd645e16386eb226d0f10c8731shiqian else 5214b6829f0d28990dd645e16386eb226d0f10c8731shiqian Bits &= ~ModulePrivateFlag; 5224b6829f0d28990dd645e16386eb226d0f10c8731shiqian NextInContextAndBits.setInt(Bits); 5234b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 5244b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5254b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Set the owning module ID. 5264b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setOwningModuleID(unsigned ID) { 5274b6829f0d28990dd645e16386eb226d0f10c8731shiqian assert(isFromASTFile() && "Only works on a deserialized declaration"); 5284b6829f0d28990dd645e16386eb226d0f10c8731shiqian *((unsigned*)this - 2) = ID; 5294b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 5304b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5314b6829f0d28990dd645e16386eb226d0f10c8731shiqianpublic: 5324b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5334b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determine the availability of the given declaration. 5344b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 5354b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// This routine will determine the most restrictive availability of 5364b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// the given declaration (e.g., preferring 'unavailable' to 5374b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 'deprecated'). 5384b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 5394b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \param Message If non-NULL and the result is not \c 5404b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// AR_Available, will be set to a (possibly empty) message 5414b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// describing why the declaration has not been introduced, is 5424b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// deprecated, or is unavailable. 5434b6829f0d28990dd645e16386eb226d0f10c8731shiqian AvailabilityResult getAvailability(std::string *Message = 0) const; 5444b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5454b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determine whether this declaration is marked 'deprecated'. 5464b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 5474b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \param Message If non-NULL and the declaration is deprecated, 5484b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// this will be set to the message describing why the declaration 5494b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// was deprecated (which may be empty). 5504b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isDeprecated(std::string *Message = 0) const { 5514b6829f0d28990dd645e16386eb226d0f10c8731shiqian return getAvailability(Message) == AR_Deprecated; 5524b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 5534b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5544b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determine whether this declaration is marked 'unavailable'. 5554b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 5564b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \param Message If non-NULL and the declaration is unavailable, 5574b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// this will be set to the message describing why the declaration 5584b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// was made unavailable (which may be empty). 5594b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isUnavailable(std::string *Message = 0) const { 5604b6829f0d28990dd645e16386eb226d0f10c8731shiqian return getAvailability(Message) == AR_Unavailable; 5614b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 5624b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5634b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determine whether this is a weak-imported symbol. 5644b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 5654b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// Weak-imported symbols are typically marked with the 5664b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 'weak_import' attribute, but may also be marked with an 5674b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 'availability' attribute where we're targing a platform prior to 5684b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// the introduction of this feature. 5694b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isWeakImported() const; 5704b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5714b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determines whether this symbol can be weak-imported, 5724b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// e.g., whether it would be well-formed to add the weak_import 5734b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// attribute. 5744b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 5754b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \param IsDefinition Set to \c true to indicate that this 5764b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// declaration cannot be weak-imported because it has a definition. 5774b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool canBeWeakImported(bool &IsDefinition) const; 5784b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5794b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determine whether this declaration came from an AST file (such as 5804b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// a precompiled header or module) rather than having been parsed. 5814b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isFromASTFile() const { return FromASTFile; } 5824b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5834b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Retrieve the global declaration ID associated with this 5844b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// declaration, which specifies where in the 5854b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned getGlobalID() const { 5864b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (isFromASTFile()) 5874b6829f0d28990dd645e16386eb226d0f10c8731shiqian return *((const unsigned*)this - 1); 5884b6829f0d28990dd645e16386eb226d0f10c8731shiqian return 0; 5894b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 5904b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5914b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Retrieve the global ID of the module that owns this particular 5924b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// declaration. 5934b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned getOwningModuleID() const { 5944b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (isFromASTFile()) 5954b6829f0d28990dd645e16386eb226d0f10c8731shiqian return *((const unsigned*)this - 2); 5964b6829f0d28990dd645e16386eb226d0f10c8731shiqian 5974b6829f0d28990dd645e16386eb226d0f10c8731shiqian return 0; 5984b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 5994b6829f0d28990dd645e16386eb226d0f10c8731shiqian 6004b6829f0d28990dd645e16386eb226d0f10c8731shiqianprivate: 6014b6829f0d28990dd645e16386eb226d0f10c8731shiqian Module *getOwningModuleSlow() const; 602636f903d84ec28714cb3d84a346dfb58f5bc99d3vladlosev 6034b6829f0d28990dd645e16386eb226d0f10c8731shiqianpublic: 6044b6829f0d28990dd645e16386eb226d0f10c8731shiqian Module *getOwningModule() const { 605636f903d84ec28714cb3d84a346dfb58f5bc99d3vladlosev if (!isFromASTFile()) 6064b6829f0d28990dd645e16386eb226d0f10c8731shiqian return 0; 607636f903d84ec28714cb3d84a346dfb58f5bc99d3vladlosev 608636f903d84ec28714cb3d84a346dfb58f5bc99d3vladlosev return getOwningModuleSlow(); 609636f903d84ec28714cb3d84a346dfb58f5bc99d3vladlosev } 6104b6829f0d28990dd645e16386eb226d0f10c8731shiqian 6114b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned getIdentifierNamespace() const { 6124b6829f0d28990dd645e16386eb226d0f10c8731shiqian return IdentifierNamespace; 6134b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 6147a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com bool isInIdentifierNamespace(unsigned NS) const { 6157a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com return getIdentifierNamespace() & NS; 6164b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 6174b6829f0d28990dd645e16386eb226d0f10c8731shiqian static unsigned getIdentifierNamespaceForKind(Kind DK); 6184b6829f0d28990dd645e16386eb226d0f10c8731shiqian 6194b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool hasTagIdentifierNamespace() const { 6204b6829f0d28990dd645e16386eb226d0f10c8731shiqian return isTagIdentifierNamespace(getIdentifierNamespace()); 6214b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 6224b6829f0d28990dd645e16386eb226d0f10c8731shiqian static bool isTagIdentifierNamespace(unsigned NS) { 6234b6829f0d28990dd645e16386eb226d0f10c8731shiqian // TagDecls have Tag and Type set and may also have TagFriend. 6247a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type); 6257a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com } 6264b6829f0d28990dd645e16386eb226d0f10c8731shiqian 627733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// getLexicalDeclContext - The declaration context where this Decl was 628733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// lexically declared (LexicalDC). May be different from 6294b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// getDeclContext() (SemanticDC). 6304b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// e.g.: 631733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// 632733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// namespace A { 633733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// void f(); // SemanticDC == LexicalDC == 'namespace A' 6344b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// } 6354b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// void A::f(); // SemanticDC == namespace 'A' 636733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// // LexicalDC == global namespace 637733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan DeclContext *getLexicalDeclContext() { 6384b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (isInSemaDC()) 6394b6829f0d28990dd645e16386eb226d0f10c8731shiqian return getSemanticDC(); 6407a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com return getMultipleDC()->LexicalDC; 6417a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com } 6427a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com const DeclContext *getLexicalDeclContext() const { 6434b6829f0d28990dd645e16386eb226d0f10c8731shiqian return const_cast<Decl*>(this)->getLexicalDeclContext(); 6444b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 6457a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com 6467a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com virtual bool isOutOfLine() const { 647b5150233bec111306f340bf486a1a0624b3a817eshiqian return getLexicalDeclContext() != getDeclContext(); 6484b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 6494b6829f0d28990dd645e16386eb226d0f10c8731shiqian 6507a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com /// setDeclContext - Set both the semantic and lexical DeclContext 6517a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com /// to DC. 6524b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setDeclContext(DeclContext *DC); 653733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 654733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan void setLexicalDeclContext(DeclContext *DC); 6554b6829f0d28990dd645e16386eb226d0f10c8731shiqian 6564b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this 657733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// scoped decl is defined outside the current function or method. This is 658733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// roughly global variables and functions, but also handles enums (which 659733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// could be defined inside or outside a function etc). 6604b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isDefinedOutsideFunctionOrMethod() const { 6614b6829f0d28990dd645e16386eb226d0f10c8731shiqian return getParentFunctionOrMethod() == 0; 662733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan } 663733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 6644b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief If this decl is defined inside a function/method/block it returns 6654b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// the corresponding DeclContext, otherwise it returns null. 666733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan const DeclContext *getParentFunctionOrMethod() const; 6674b6829f0d28990dd645e16386eb226d0f10c8731shiqian DeclContext *getParentFunctionOrMethod() { 6684b6829f0d28990dd645e16386eb226d0f10c8731shiqian return const_cast<DeclContext*>( 6694b6829f0d28990dd645e16386eb226d0f10c8731shiqian const_cast<const Decl*>(this)->getParentFunctionOrMethod()); 6704b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 6714b6829f0d28990dd645e16386eb226d0f10c8731shiqian 6724b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Retrieves the "canonical" declaration of the given declaration. 6734b6829f0d28990dd645e16386eb226d0f10c8731shiqian virtual Decl *getCanonicalDecl() { return this; } 674733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan const Decl *getCanonicalDecl() const { 675dd617c1bc8e67a915068e8462881fbc5e2f6ae30zhanyong.wan return const_cast<Decl*>(this)->getCanonicalDecl(); 676c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan } 677c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 678c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// \brief Whether this particular Decl is a canonical one. 679c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan bool isCanonicalDecl() const { return getCanonicalDecl() == this; } 680c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 681c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wanprotected: 682c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// \brief Returns the next redeclaration or itself if this is the only decl. 683c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// 684c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// Decl subclasses that can be redeclared should override this method so that 685733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// Decl::redecl_iterator can iterate over them. 686c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan virtual Decl *getNextRedeclaration() { return this; } 6874b6829f0d28990dd645e16386eb226d0f10c8731shiqian 6884b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Implementation of getPreviousDecl(), to be overridden by any 6894b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// subclass that has a redeclaration chain. 6904b6829f0d28990dd645e16386eb226d0f10c8731shiqian virtual Decl *getPreviousDeclImpl() { return 0; } 6914b6829f0d28990dd645e16386eb226d0f10c8731shiqian 6924b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Implementation of getMostRecentDecl(), to be overridden by any 6934b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// subclass that has a redeclaration chain. 6944b6829f0d28990dd645e16386eb226d0f10c8731shiqian virtual Decl *getMostRecentDeclImpl() { return this; } 6954b6829f0d28990dd645e16386eb226d0f10c8731shiqian 6964b6829f0d28990dd645e16386eb226d0f10c8731shiqianpublic: 697d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// \brief Iterates through all the redeclarations of the same decl. 698d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com class redecl_iterator { 699d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// Current - The current declaration. 700d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com Decl *Current; 7014b6829f0d28990dd645e16386eb226d0f10c8731shiqian Decl *Starter; 7024b6829f0d28990dd645e16386eb226d0f10c8731shiqian 7034b6829f0d28990dd645e16386eb226d0f10c8731shiqian public: 7044b6829f0d28990dd645e16386eb226d0f10c8731shiqian typedef Decl *value_type; 7054b6829f0d28990dd645e16386eb226d0f10c8731shiqian typedef const value_type &reference; 7064b6829f0d28990dd645e16386eb226d0f10c8731shiqian typedef const value_type *pointer; 7074b6829f0d28990dd645e16386eb226d0f10c8731shiqian typedef std::forward_iterator_tag iterator_category; 7084b6829f0d28990dd645e16386eb226d0f10c8731shiqian typedef std::ptrdiff_t difference_type; 7094b6829f0d28990dd645e16386eb226d0f10c8731shiqian 7104b6829f0d28990dd645e16386eb226d0f10c8731shiqian redecl_iterator() : Current(0) { } 7114b6829f0d28990dd645e16386eb226d0f10c8731shiqian explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { } 7124b6829f0d28990dd645e16386eb226d0f10c8731shiqian 713d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com reference operator*() const { return Current; } 714d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com value_type operator->() const { return Current; } 715d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 716d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com redecl_iterator& operator++() { 717d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com assert(Current && "Advancing while iterator has reached end"); 718d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com // Get either previous decl or latest decl. 719d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com Decl *Next = Current->getNextRedeclaration(); 720d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com assert(Next && "Should return next redeclaration or itself, never null!"); 721d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com Current = (Next != Starter ? Next : 0); 722d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com return *this; 723d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com } 724d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 725d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com redecl_iterator operator++(int) { 726d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com redecl_iterator tmp(*this); 727d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com ++(*this); 728d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com return tmp; 729d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com } 730d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 731d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com friend bool operator==(redecl_iterator x, redecl_iterator y) { 732d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com return x.Current == y.Current; 733d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com } 734d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com friend bool operator!=(redecl_iterator x, redecl_iterator y) { 735d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com return x.Current != y.Current; 736d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com } 737d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com }; 738d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 739d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// \brief Returns iterator for all the redeclarations of the same decl. 740d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// It will iterate at least once (when this decl is the only one). 741d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com redecl_iterator redecls_begin() const { 742d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com return redecl_iterator(const_cast<Decl*>(this)); 743d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com } 744d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com redecl_iterator redecls_end() const { return redecl_iterator(); } 745d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 746d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// \brief Retrieve the previous declaration that declares the same entity 747d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// as this declaration, or NULL if there is no previous declaration. 748d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com Decl *getPreviousDecl() { return getPreviousDeclImpl(); } 749d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 750d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// \brief Retrieve the most recent declaration that declares the same entity 751d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// as this declaration, or NULL if there is no previous declaration. 752d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com const Decl *getPreviousDecl() const { 753d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com return const_cast<Decl *>(this)->getPreviousDeclImpl(); 754d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com } 755d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 756d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// \brief Retrieve the most recent declaration that declares the same entity 757d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// as this declaration (which may be this declaration). 758d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com Decl *getMostRecentDecl() { return getMostRecentDeclImpl(); } 759d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 760d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// \brief Retrieve the most recent declaration that declares the same entity 761d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// as this declaration (which may be this declaration). 762d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com const Decl *getMostRecentDecl() const { 763d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com return const_cast<Decl *>(this)->getMostRecentDeclImpl(); 764d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com } 765d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 766d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// getBody - If this Decl represents a declaration for a body of code, 767d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// such as a function or method definition, this method returns the 768d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// top-level Stmt* of that body. Otherwise this method returns null. 769d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com virtual Stmt* getBody() const { return 0; } 770d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 771d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// \brief Returns true if this Decl represents a declaration for a body of 772d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// code, such as a function or method definition. 773d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com virtual bool hasBody() const { return getBody() != 0; } 774d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com 775d132283f055f07588d82ad43fbf501645cb39c9dkosak@google.com /// getBodyRBrace - Gets the right brace of the body, if a body exists. 776733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// This works whether the body is a CompoundStmt or a CXXTryStmt. 7774b6829f0d28990dd645e16386eb226d0f10c8731shiqian SourceLocation getBodyRBrace() const; 7784b6829f0d28990dd645e16386eb226d0f10c8731shiqian 77921d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian // global temp stats (until we have a per-module visitor) 780c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian static void add(Kind k); 781c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian static void EnableStatistics(); 782c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan static void PrintStats(); 783733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 784733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// isTemplateParameter - Determines whether this declaration is a 785c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// template parameter. 786c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan bool isTemplateParameter() const; 787c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 7887a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com /// isTemplateParameter - Determines whether this declaration is a 789733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// template parameter pack. 790733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan bool isTemplateParameterPack() const; 791733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 792c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// \brief Whether this declaration is a parameter pack. 793c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan bool isParameterPack() const; 794c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 7954b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief returns true if this declaration is a template 796c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian bool isTemplateDecl() const; 7977a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com 7984b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration is a function or function template. 799733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan bool isFunctionOrFunctionTemplate() const; 800733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan 801c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// \brief Changes the namespace of this declaration to reflect that it's 802c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// the object of a friend declaration. 803c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// 8047a574c99ea1d474f8ec5f040deba54169120f063jgm@google.com /// These declarations appear in the lexical context of the friending 805c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// class, but in the semantic context of the actual entity. This property 8064b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// applies only to a specific decl object; other redeclarations of the 8074b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// same entity may not (and probably don't) share this property. 80821d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian void setObjectOfFriendDecl(bool PreviouslyDeclared) { 80921d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian unsigned OldNS = IdentifierNamespace; 81021d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian assert((OldNS & (IDNS_Tag | IDNS_Ordinary | 81121d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian IDNS_TagFriend | IDNS_OrdinaryFriend)) && 81221d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian "namespace includes neither ordinary nor tag"); 81321d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | 81421d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian IDNS_TagFriend | IDNS_OrdinaryFriend)) && 81521d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian "namespace includes other than ordinary or tag"); 81621d43d1a7e09d960b790d992f1bb4e92c70391d4shiqian 8174b6829f0d28990dd645e16386eb226d0f10c8731shiqian IdentifierNamespace = 0; 8184b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (OldNS & (IDNS_Tag | IDNS_TagFriend)) { 8194b6829f0d28990dd645e16386eb226d0f10c8731shiqian IdentifierNamespace |= IDNS_TagFriend; 820c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Tag | IDNS_Type; 8214b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 8224b6829f0d28990dd645e16386eb226d0f10c8731shiqian 8234b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend)) { 82434b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan IdentifierNamespace |= IDNS_OrdinaryFriend; 82534b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Ordinary; 82634b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan } 82734b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan } 82834b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan 82934b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan enum FriendObjectKind { 83034b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan FOK_None, // not a friend object 83134b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan FOK_Declared, // a friend of a previously-declared entity 83234b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan FOK_Undeclared // a friend of a previously-undeclared entity 83334b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan }; 83434b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan 83534b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// \brief Determines whether this declaration is the object of a 83634b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// friend declaration and, if so, what kind. 83734b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// 83834b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// There is currently no direct way to find the associated FriendDecl. 83934b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan FriendObjectKind getFriendObjectKind() const { 84034b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan unsigned mask 84134b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan = (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); 84234b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan if (!mask) return FOK_None; 84334b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? 84434b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan FOK_Declared : FOK_Undeclared); 84534b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan } 84634b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan 84734b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan /// Specifies that this declaration is a C++ overloaded non-member. 84834b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan void setNonMemberOperator() { 84934b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan assert(getKind() == Function || getKind() == FunctionTemplate); 85034b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan assert((IdentifierNamespace & IDNS_Ordinary) && 85134b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan "visible non-member operators should be in ordinary namespace"); 85234b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan IdentifierNamespace |= IDNS_NonMemberOperator; 85334b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan } 85434b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan 85534b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan static bool classofKind(Kind K) { return true; } 85634b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan static DeclContext *castToDeclContext(const Decl *); 85734b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan static Decl *castFromDeclContext(const DeclContext *); 85834b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan 85934b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan void print(raw_ostream &Out, unsigned Indentation = 0, 86034b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan bool PrintInstantiation = false) const; 86134b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan void print(raw_ostream &Out, const PrintingPolicy &Policy, 86234b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan unsigned Indentation = 0, bool PrintInstantiation = false) const; 86334b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan static void printGroup(Decl** Begin, unsigned NumDecls, 86434b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan raw_ostream &Out, const PrintingPolicy &Policy, 86534b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan unsigned Indentation = 0); 86634b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan // Debuggers don't usually respect default arguments. 86734b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan LLVM_ATTRIBUTE_USED void dump() const; 86834b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan // Same as dump(), but forces color printing. 86934b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan LLVM_ATTRIBUTE_USED void dumpColor() const; 87034b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan void dump(raw_ostream &Out) const; 87134b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan // Debuggers don't usually respect default arguments. 87234b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan LLVM_ATTRIBUTE_USED void dumpXML() const; 87334b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan void dumpXML(raw_ostream &OS) const; 87434b3f298ed6c093e36511e235fff9d7501ec4395zhanyong.wan 8754b6829f0d28990dd645e16386eb226d0f10c8731shiqianprivate: 8764b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx); 8774b6829f0d28990dd645e16386eb226d0f10c8731shiqian void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC, 8784b6829f0d28990dd645e16386eb226d0f10c8731shiqian ASTContext &Ctx); 8794b6829f0d28990dd645e16386eb226d0f10c8731shiqian 8804b6829f0d28990dd645e16386eb226d0f10c8731shiqianprotected: 8814b6829f0d28990dd645e16386eb226d0f10c8731shiqian ASTMutationListener *getASTMutationListener() const; 8824b6829f0d28990dd645e16386eb226d0f10c8731shiqian}; 8834b6829f0d28990dd645e16386eb226d0f10c8731shiqian 8844b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// \brief Determine whether two declarations declare the same entity. 8854b6829f0d28990dd645e16386eb226d0f10c8731shiqianinline bool declaresSameEntity(const Decl *D1, const Decl *D2) { 8864b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (!D1 || !D2) 8874b6829f0d28990dd645e16386eb226d0f10c8731shiqian return false; 8884b6829f0d28990dd645e16386eb226d0f10c8731shiqian 8894b6829f0d28990dd645e16386eb226d0f10c8731shiqian if (D1 == D2) 8904b6829f0d28990dd645e16386eb226d0f10c8731shiqian return true; 8914b6829f0d28990dd645e16386eb226d0f10c8731shiqian 8924b6829f0d28990dd645e16386eb226d0f10c8731shiqian return D1->getCanonicalDecl() == D2->getCanonicalDecl(); 8934b6829f0d28990dd645e16386eb226d0f10c8731shiqian} 8944b6829f0d28990dd645e16386eb226d0f10c8731shiqian 8954b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when 8964b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// doing something to a specific decl. 8974b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { 8984b6829f0d28990dd645e16386eb226d0f10c8731shiqian const Decl *TheDecl; 8994b6829f0d28990dd645e16386eb226d0f10c8731shiqian SourceLocation Loc; 9004b6829f0d28990dd645e16386eb226d0f10c8731shiqian SourceManager &SM; 9014b6829f0d28990dd645e16386eb226d0f10c8731shiqian const char *Message; 9024b6829f0d28990dd645e16386eb226d0f10c8731shiqianpublic: 9034b6829f0d28990dd645e16386eb226d0f10c8731shiqian PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, 9044b6829f0d28990dd645e16386eb226d0f10c8731shiqian SourceManager &sm, const char *Msg) 9054b6829f0d28990dd645e16386eb226d0f10c8731shiqian : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} 9064b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9074b6829f0d28990dd645e16386eb226d0f10c8731shiqian virtual void print(raw_ostream &OS) const; 9084b6829f0d28990dd645e16386eb226d0f10c8731shiqian}; 9094b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9104b6829f0d28990dd645e16386eb226d0f10c8731shiqiantypedef llvm::MutableArrayRef<NamedDecl*> DeclContextLookupResult; 9114b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9124b6829f0d28990dd645e16386eb226d0f10c8731shiqiantypedef ArrayRef<NamedDecl *> DeclContextLookupConstResult; 9134b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9144b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// DeclContext - This is used only as base class of specific decl types that 9154b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// can act as declaration contexts. These decls are (only the top classes 9164b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// that directly derive from DeclContext are mentioned, not their subclasses): 9174b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// 9184b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// TranslationUnitDecl 9194b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// NamespaceDecl 9204b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// FunctionDecl 9214b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// TagDecl 9224b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// ObjCMethodDecl 9234b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// ObjCContainerDecl 9244b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// LinkageSpecDecl 9254b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// BlockDecl 9264b6829f0d28990dd645e16386eb226d0f10c8731shiqian/// 9274b6829f0d28990dd645e16386eb226d0f10c8731shiqianclass DeclContext { 9284b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// DeclKind - This indicates which class this is. 9294b6829f0d28990dd645e16386eb226d0f10c8731shiqian unsigned DeclKind : 8; 9304b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9314b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration context also has some external 9324b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// storage that contains additional declarations that are lexically 9334b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// part of this context. 9344b6829f0d28990dd645e16386eb226d0f10c8731shiqian mutable bool ExternalLexicalStorage : 1; 9354b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9364b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration context also has some external 9374b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// storage that contains additional declarations that are visible 9384b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// in this context. 9394b6829f0d28990dd645e16386eb226d0f10c8731shiqian mutable bool ExternalVisibleStorage : 1; 9404b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9414b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Whether this declaration context has had external visible 9424b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// storage added since the last lookup. In this case, \c LookupPtr's 9434b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// invariant may not hold and needs to be fixed before we perform 9444b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// another lookup. 9454b6829f0d28990dd645e16386eb226d0f10c8731shiqian mutable bool NeedToReconcileExternalVisibleStorage : 1; 9464b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9474b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Pointer to the data structure used to lookup declarations 9484b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// within this context (or a DependentStoredDeclsMap if this is a 9494b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// dependent context), and a bool indicating whether we have lazily 9504b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// omitted any declarations from the map. We maintain the invariant 9514b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// that, if the map contains an entry for a DeclarationName (and we 9524b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// haven't lazily omitted anything), then it contains all relevant 9534b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// entries for that name. 95493fed47dbf8e6bc3d39d3f769cb5039551747257vladlosev mutable llvm::PointerIntPair<StoredDeclsMap*, 1, bool> LookupPtr; 9554b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9564b6829f0d28990dd645e16386eb226d0f10c8731shiqianprotected: 9574b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// FirstDecl - The first declaration stored within this declaration 9584b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// context. 9594b6829f0d28990dd645e16386eb226d0f10c8731shiqian mutable Decl *FirstDecl; 9604b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9614b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// LastDecl - The last declaration stored within this declaration 9624b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// context. FIXME: We could probably cache this value somewhere 9634b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// outside of the DeclContext, to reduce the size of DeclContext by 9644b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// another pointer. 9654b6829f0d28990dd645e16386eb226d0f10c8731shiqian mutable Decl *LastDecl; 9664b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9674b6829f0d28990dd645e16386eb226d0f10c8731shiqian friend class ExternalASTSource; 9684b6829f0d28990dd645e16386eb226d0f10c8731shiqian friend class ASTWriter; 9694b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9704b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Build up a chain of declarations. 9714b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 9724b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \returns the first/last pair of declarations. 9734b6829f0d28990dd645e16386eb226d0f10c8731shiqian static std::pair<Decl *, Decl *> 9744b6829f0d28990dd645e16386eb226d0f10c8731shiqian BuildDeclChain(ArrayRef<Decl*> Decls, bool FieldsAlreadyLoaded); 9754b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9764b6829f0d28990dd645e16386eb226d0f10c8731shiqian DeclContext(Decl::Kind K) 9774b6829f0d28990dd645e16386eb226d0f10c8731shiqian : DeclKind(K), ExternalLexicalStorage(false), 9784b6829f0d28990dd645e16386eb226d0f10c8731shiqian ExternalVisibleStorage(false), 9794b6829f0d28990dd645e16386eb226d0f10c8731shiqian NeedToReconcileExternalVisibleStorage(false), LookupPtr(0, false), 9804b6829f0d28990dd645e16386eb226d0f10c8731shiqian FirstDecl(0), LastDecl(0) {} 9814b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9824b6829f0d28990dd645e16386eb226d0f10c8731shiqianpublic: 9834b6829f0d28990dd645e16386eb226d0f10c8731shiqian ~DeclContext(); 9844b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9854b6829f0d28990dd645e16386eb226d0f10c8731shiqian Decl::Kind getDeclKind() const { 9864b6829f0d28990dd645e16386eb226d0f10c8731shiqian return static_cast<Decl::Kind>(DeclKind); 9874b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 9884b6829f0d28990dd645e16386eb226d0f10c8731shiqian const char *getDeclKindName() const; 9894b6829f0d28990dd645e16386eb226d0f10c8731shiqian 9904b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// getParent - Returns the containing DeclContext. 9914b6829f0d28990dd645e16386eb226d0f10c8731shiqian DeclContext *getParent() { 9924b6829f0d28990dd645e16386eb226d0f10c8731shiqian return cast<Decl>(this)->getDeclContext(); 9934b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 9944b6829f0d28990dd645e16386eb226d0f10c8731shiqian const DeclContext *getParent() const { 99537ce949fb6ee00109391035835d4893a94f250a9zhanyong.wan return const_cast<DeclContext*>(this)->getParent(); 99637ce949fb6ee00109391035835d4893a94f250a9zhanyong.wan } 99737ce949fb6ee00109391035835d4893a94f250a9zhanyong.wan 99837ce949fb6ee00109391035835d4893a94f250a9zhanyong.wan /// getLexicalParent - Returns the containing lexical DeclContext. May be 9994b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// different from getParent, e.g.: 10004b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 10014b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// namespace A { 10024b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// struct S; 10034b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// } 10044b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// struct A::S {}; // getParent() == namespace 'A' 10054b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// // getLexicalParent() == translation unit 10064b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// 10074b6829f0d28990dd645e16386eb226d0f10c8731shiqian DeclContext *getLexicalParent() { 10084b6829f0d28990dd645e16386eb226d0f10c8731shiqian return cast<Decl>(this)->getLexicalDeclContext(); 1009e44602ec83c65102035ce5304ae8de0cb16e9e56shiqian } 10104b6829f0d28990dd645e16386eb226d0f10c8731shiqian const DeclContext *getLexicalParent() const { 10114b6829f0d28990dd645e16386eb226d0f10c8731shiqian return const_cast<DeclContext*>(this)->getLexicalParent(); 10124b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10134b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10144b6829f0d28990dd645e16386eb226d0f10c8731shiqian DeclContext *getLookupParent(); 10154b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10164b6829f0d28990dd645e16386eb226d0f10c8731shiqian const DeclContext *getLookupParent() const { 10174b6829f0d28990dd645e16386eb226d0f10c8731shiqian return const_cast<DeclContext*>(this)->getLookupParent(); 10184b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 1019a80f23f103e1a008c1df7ecc68eef9aa4ffbdc37zhanyong.wan 10204b6829f0d28990dd645e16386eb226d0f10c8731shiqian ASTContext &getParentASTContext() const { 10214b6829f0d28990dd645e16386eb226d0f10c8731shiqian return cast<Decl>(this)->getASTContext(); 10224b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10234b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10244b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isClosure() const { 10254b6829f0d28990dd645e16386eb226d0f10c8731shiqian return DeclKind == Decl::Block; 10264b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10274b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10284b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isObjCContainer() const { 10294b6829f0d28990dd645e16386eb226d0f10c8731shiqian switch (DeclKind) { 10304b6829f0d28990dd645e16386eb226d0f10c8731shiqian case Decl::ObjCCategory: 10314b6829f0d28990dd645e16386eb226d0f10c8731shiqian case Decl::ObjCCategoryImpl: 10324b6829f0d28990dd645e16386eb226d0f10c8731shiqian case Decl::ObjCImplementation: 10334b6829f0d28990dd645e16386eb226d0f10c8731shiqian case Decl::ObjCInterface: 10344b6829f0d28990dd645e16386eb226d0f10c8731shiqian case Decl::ObjCProtocol: 10354b6829f0d28990dd645e16386eb226d0f10c8731shiqian return true; 10364b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10374b6829f0d28990dd645e16386eb226d0f10c8731shiqian return false; 10384b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10394b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10404b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isFunctionOrMethod() const { 10414b6829f0d28990dd645e16386eb226d0f10c8731shiqian switch (DeclKind) { 10424b6829f0d28990dd645e16386eb226d0f10c8731shiqian case Decl::Block: 10434b6829f0d28990dd645e16386eb226d0f10c8731shiqian case Decl::ObjCMethod: 10444b6829f0d28990dd645e16386eb226d0f10c8731shiqian return true; 10454b6829f0d28990dd645e16386eb226d0f10c8731shiqian default: 10464b6829f0d28990dd645e16386eb226d0f10c8731shiqian return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction; 10474b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10484b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10494b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10504b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isFileContext() const { 10514b6829f0d28990dd645e16386eb226d0f10c8731shiqian return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 10524b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10534b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10544b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isTranslationUnit() const { 10554b6829f0d28990dd645e16386eb226d0f10c8731shiqian return DeclKind == Decl::TranslationUnit; 10564b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10574b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10584b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isRecord() const { 10594b6829f0d28990dd645e16386eb226d0f10c8731shiqian return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord; 10604b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10614b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10624b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isNamespace() const { 10634b6829f0d28990dd645e16386eb226d0f10c8731shiqian return DeclKind == Decl::Namespace; 10644b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 10654b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10664b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isInlineNamespace() const; 10674b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10684b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determines whether this context is dependent on a 10694b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// template parameter. 10704b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isDependentContext() const; 10714b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10724b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// isTransparentContext - Determines whether this context is a 10734b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// "transparent" context, meaning that the members declared in this 10744b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// context are semantically declared in the nearest enclosing 10754b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// non-transparent (opaque) context but are lexically declared in 10764b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// this context. For example, consider the enumerators of an 10774b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// enumeration type: 10784b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// @code 10794b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// enum E { 10804b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// Val1 10814b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// }; 10824b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// @endcode 10834b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// Here, E is a transparent context, so its enumerator (Val1) will 10844b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// appear (semantically) that it is in the same context of E. 10854b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// Examples of transparent contexts include: enumerations (except for 10864b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// C++0x scoped enums), and C++ linkage specifications. 10874b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isTransparentContext() const; 10884b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10894b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determines whether this context is, or is nested within, 10904b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// a C++ extern "C" linkage spec. 10914b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isExternCContext() const; 10924b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10934b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determines whether this context is, or is nested within, 10944b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// a C++ extern "C++" linkage spec. 10954b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool isExternCXXContext() const; 10964b6829f0d28990dd645e16386eb226d0f10c8731shiqian 10974b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determine whether this declaration context is equivalent 10984b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// to the declaration context DC. 10994b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool Equals(const DeclContext *DC) const { 11004b6829f0d28990dd645e16386eb226d0f10c8731shiqian return DC && this->getPrimaryContext() == DC->getPrimaryContext(); 11014b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 11024b6829f0d28990dd645e16386eb226d0f10c8731shiqian 11034b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Determine whether this declaration context encloses the 11044b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// declaration context DC. 11054b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool Encloses(const DeclContext *DC) const; 11064b6829f0d28990dd645e16386eb226d0f10c8731shiqian 11074b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Find the nearest non-closure ancestor of this context, 11084b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// i.e. the innermost semantic parent of this context which is not 11094b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// a closure. A context may be its own non-closure ancestor. 11104b6829f0d28990dd645e16386eb226d0f10c8731shiqian DeclContext *getNonClosureAncestor(); 11114b6829f0d28990dd645e16386eb226d0f10c8731shiqian const DeclContext *getNonClosureAncestor() const { 11124b6829f0d28990dd645e16386eb226d0f10c8731shiqian return const_cast<DeclContext*>(this)->getNonClosureAncestor(); 11134b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 11144b6829f0d28990dd645e16386eb226d0f10c8731shiqian 11154b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// getPrimaryContext - There may be many different 11164b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// declarations of the same entity (including forward declarations 11174b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// of classes, multiple definitions of namespaces, etc.), each with 11184b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// a different set of declarations. This routine returns the 1119c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian /// "primary" DeclContext structure, which will contain the 11204b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// information needed to perform name lookup into this context. 11214b6829f0d28990dd645e16386eb226d0f10c8731shiqian DeclContext *getPrimaryContext(); 11224b6829f0d28990dd645e16386eb226d0f10c8731shiqian const DeclContext *getPrimaryContext() const { 11234b6829f0d28990dd645e16386eb226d0f10c8731shiqian return const_cast<DeclContext*>(this)->getPrimaryContext(); 11244b6829f0d28990dd645e16386eb226d0f10c8731shiqian } 11254b6829f0d28990dd645e16386eb226d0f10c8731shiqian 11264b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// getRedeclContext - Retrieve the context in which an entity conflicts with 11274b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// other entities of the same name, or where it is a redeclaration if the 11284b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// two entities are compatible. This skips through transparent contexts. 11294b6829f0d28990dd645e16386eb226d0f10c8731shiqian DeclContext *getRedeclContext(); 11304b6829f0d28990dd645e16386eb226d0f10c8731shiqian const DeclContext *getRedeclContext() const { 11314b6829f0d28990dd645e16386eb226d0f10c8731shiqian return const_cast<DeclContext *>(this)->getRedeclContext(); 1132c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian } 11331cdc76325936ad3312be0d456b4936c8b8e6bf70zhanyong.wan 11344b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// \brief Retrieve the nearest enclosing namespace context. 11354b6829f0d28990dd645e16386eb226d0f10c8731shiqian DeclContext *getEnclosingNamespaceContext(); 11364b6829f0d28990dd645e16386eb226d0f10c8731shiqian const DeclContext *getEnclosingNamespaceContext() const { 1137c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); 1138c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian } 11394b6829f0d28990dd645e16386eb226d0f10c8731shiqian 1140c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian /// \brief Test if this context is part of the enclosing namespace set of 11414b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// the context NS, as defined in C++0x [namespace.def]p9. If either context 11424b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// isn't a namespace, this is equivalent to Equals(). 1143c3b4de35a18a1f011e8009d4d794f787f7e4e0c1shiqian /// 11444b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// The enclosing namespace set of a namespace is the namespace and, if it is 11454b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// inline, its enclosing namespace, recursively. 11464b6829f0d28990dd645e16386eb226d0f10c8731shiqian bool InEnclosingNamespaceSetOf(const DeclContext *NS) const; 1147b0b40063a828ca7a4ceb079ecd508775c6aa9d93zhanyong.wan 1148c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// \brief Collects all of the declaration contexts that are semantically 1149b0b40063a828ca7a4ceb079ecd508775c6aa9d93zhanyong.wan /// connected to this declaration context. 1150c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// 1151b0b40063a828ca7a4ceb079ecd508775c6aa9d93zhanyong.wan /// For declaration contexts that have multiple semantically connected but 1152c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// syntactically distinct contexts, such as C++ namespaces, this routine 1153b0b40063a828ca7a4ceb079ecd508775c6aa9d93zhanyong.wan /// retrieves the complete set of such declaration contexts in source order. 1154c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// For example, given: 1155c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// 1156733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan /// \code 1157c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// namespace N { 1158c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// int x; 1159c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// } 1160c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// namespace N { 1161c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// int y; 1162c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// } 1163c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// \endcode 1164c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// 1165c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// The \c Contexts parameter will contain both definitions of N. 1166c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// 1167c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// \param Contexts Will be cleared and set to the set of declaration 1168c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// contexts that are semanticaly connected to this declaration context, 1169c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// in source order, including this context (which may be the only result, 1170c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// for non-namespace contexts). 1171c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan void collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts); 1172c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1173c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// decl_iterator - Iterates through the declarations stored 1174c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// within this context. 1175c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan class decl_iterator { 1176c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// Current - The current declaration. 1177c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan Decl *Current; 1178c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1179c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan public: 1180c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan typedef Decl *value_type; 1181733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan typedef const value_type &reference; 1182c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan typedef const value_type *pointer; 1183733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan typedef std::forward_iterator_tag iterator_category; 1184c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan typedef std::ptrdiff_t difference_type; 1185c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1186733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan decl_iterator() : Current(0) { } 1187c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan explicit decl_iterator(Decl *C) : Current(C) { } 1188c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1189733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan reference operator*() const { return Current; } 1190c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan // This doesn't meet the iterator requirements, but it's convenient 1191be1b3b66822cc3929f3da700973cef88bf45849azhanyong.wan value_type operator->() const { return Current; } 1192be1b3b66822cc3929f3da700973cef88bf45849azhanyong.wan 1193be1b3b66822cc3929f3da700973cef88bf45849azhanyong.wan decl_iterator& operator++() { 1194be1b3b66822cc3929f3da700973cef88bf45849azhanyong.wan Current = Current->getNextDeclInContext(); 1195be1b3b66822cc3929f3da700973cef88bf45849azhanyong.wan return *this; 1196c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan } 1197c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1198c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan decl_iterator operator++(int) { 1199c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan decl_iterator tmp(*this); 120003c314931649a999b0cf5deb0a434a1009157416jgm@google.com ++(*this); 1201c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan return tmp; 1202c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan } 120303c314931649a999b0cf5deb0a434a1009157416jgm@google.com 1204c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan friend bool operator==(decl_iterator x, decl_iterator y) { 1205c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan return x.Current == y.Current; 120603c314931649a999b0cf5deb0a434a1009157416jgm@google.com } 1207c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan friend bool operator!=(decl_iterator x, decl_iterator y) { 1208c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan return x.Current != y.Current; 120903c314931649a999b0cf5deb0a434a1009157416jgm@google.com } 1210c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan }; 1211c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1212c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// decls_begin/decls_end - Iterate over the declarations stored in 1213c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// this context. 1214c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan decl_iterator decls_begin() const; 1215c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan decl_iterator decls_end() const { return decl_iterator(); } 121603c314931649a999b0cf5deb0a434a1009157416jgm@google.com bool decls_empty() const; 1217c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1218c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// noload_decls_begin/end - Iterate over the declarations stored in this 121903c314931649a999b0cf5deb0a434a1009157416jgm@google.com /// context that are currently loaded; don't attempt to retrieve anything 1220c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// from an external source. 1221c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan decl_iterator noload_decls_begin() const; 1222c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan decl_iterator noload_decls_end() const { return decl_iterator(); } 1223c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1224c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// specific_decl_iterator - Iterates over a subrange of 1225c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// declarations stored in a DeclContext, providing only those that 1226c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// are of type SpecificDecl (or a class derived from it). This 122703c314931649a999b0cf5deb0a434a1009157416jgm@google.com /// iterator is used, for example, to provide iteration over just 1228a773ef8a3b70936450c94bdcba1e6345a980244ezhanyong.wan /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). 1229c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan template<typename SpecificDecl> 1230c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan class specific_decl_iterator { 1231c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// Current - The current, underlying declaration iterator, which 123203c314931649a999b0cf5deb0a434a1009157416jgm@google.com /// will either be NULL or will point to a declaration of 1233a773ef8a3b70936450c94bdcba1e6345a980244ezhanyong.wan /// type SpecificDecl. 1234c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan DeclContext::decl_iterator Current; 1235c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 123603c314931649a999b0cf5deb0a434a1009157416jgm@google.com /// SkipToNextDecl - Advances the current position up to the next 1237a773ef8a3b70936450c94bdcba1e6345a980244ezhanyong.wan /// declaration of type SpecificDecl that also meets the criteria 1238c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// required by Acceptable. 1239c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan void SkipToNextDecl() { 1240c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan while (*Current && !isa<SpecificDecl>(*Current)) 1241c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan ++Current; 1242c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan } 1243c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1244c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan public: 1245c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan typedef SpecificDecl *value_type; 1246c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan // TODO: Add reference and pointer typedefs (with some appropriate proxy 1247c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan // type) if we ever have a need for them. 1248c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan typedef void reference; 1249c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan typedef void pointer; 1250c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 1251c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan difference_type; 1252c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan typedef std::forward_iterator_tag iterator_category; 1253c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1254c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan specific_decl_iterator() : Current() { } 1255c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1256c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// specific_decl_iterator - Construct a new iterator over a 1257c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// subset of the declarations the range [C, 1258c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// end-of-declarations). If A is non-NULL, it is a pointer to a 1259c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// member function of SpecificDecl that should return true for 1260c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// all of the SpecificDecl instances that will be in the subset 1261c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// of iterators. For example, if you want Objective-C instance 1262c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// methods, SpecificDecl will be ObjCMethodDecl and A will be 1263c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan /// &ObjCMethodDecl::isInstanceMethod. 1264c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 1265c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan SkipToNextDecl(); 1266c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan } 1267c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1268c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan value_type operator*() const { return cast<SpecificDecl>(*Current); } 1269c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan // This doesn't meet the iterator requirements, but it's convenient 1270c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan value_type operator->() const { return **this; } 1271c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 127203c314931649a999b0cf5deb0a434a1009157416jgm@google.com specific_decl_iterator& operator++() { 1273c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan ++Current; 1274c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan SkipToNextDecl(); 1275c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan return *this; 127603c314931649a999b0cf5deb0a434a1009157416jgm@google.com } 1277c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1278c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan specific_decl_iterator operator++(int) { 1279c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan specific_decl_iterator tmp(*this); 1280733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan ++(*this); 1281c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan return tmp; 1282c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan } 1283c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1284c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan friend bool operator==(const specific_decl_iterator& x, 1285c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan const specific_decl_iterator& y) { 1286c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan return x.Current == y.Current; 1287733a54a398766289b74cf3daebe083d7115cf388zhanyong.wan } 1288c85c0c20322a1f36113cf4d6282908e16ca32669zhanyong.wan 1289535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan friend bool operator!=(const specific_decl_iterator& x, 1290535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan const specific_decl_iterator& y) { 1291535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan return x.Current != y.Current; 1292b1fc4d36385c457e2237e778859759219f1604b6vladlosev } 1293b1fc4d36385c457e2237e778859759219f1604b6vladlosev }; 1294b1fc4d36385c457e2237e778859759219f1604b6vladlosev 1295b1fc4d36385c457e2237e778859759219f1604b6vladlosev /// \brief Iterates over a filtered subrange of declarations stored 1296535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// in a DeclContext. 1297535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// 1298535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// This iterator visits only those declarations that are of type 1299535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// SpecificDecl (or a class derived from it) and that meet some 1300535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// additional run-time criteria. This iterator is used, for 1301535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// example, to provide access to the instance methods within an 1302f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and 1303f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// Acceptable = ObjCMethodDecl::isInstanceMethod). 1304f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> 1305f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com class filtered_decl_iterator { 1306f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// Current - The current, underlying declaration iterator, which 1307f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// will either be NULL or will point to a declaration of 1308f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// type SpecificDecl. 1309f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com DeclContext::decl_iterator Current; 1310f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com 1311f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// SkipToNextDecl - Advances the current position up to the next 1312f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// declaration of type SpecificDecl that also meets the criteria 1313f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// required by Acceptable. 1314f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com void SkipToNextDecl() { 1315f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com while (*Current && 1316f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com (!isa<SpecificDecl>(*Current) || 1317f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) 1318f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com ++Current; 1319f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com } 1320f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com 1321f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com public: 1322f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com typedef SpecificDecl *value_type; 1323535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan // TODO: Add reference and pointer typedefs (with some appropriate proxy 1324535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan // type) if we ever have a need for them. 1325535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan typedef void reference; 1326535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan typedef void pointer; 1327535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type 1328d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan difference_type; 1329535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan typedef std::forward_iterator_tag iterator_category; 1330535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan 1331535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan filtered_decl_iterator() : Current() { } 1332535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan 1333535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// filtered_decl_iterator - Construct a new iterator over a 1334535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// subset of the declarations the range [C, 133503c314931649a999b0cf5deb0a434a1009157416jgm@google.com /// end-of-declarations). If A is non-NULL, it is a pointer to a 1336535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// member function of SpecificDecl that should return true for 1337535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// all of the SpecificDecl instances that will be in the subset 1338535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// of iterators. For example, if you want Objective-C instance 1339535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan /// methods, SpecificDecl will be ObjCMethodDecl and A will be 1340d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// &ObjCMethodDecl::isInstanceMethod. 1341535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { 1342d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan SkipToNextDecl(); 1343d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan } 1344d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan 1345d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan value_type operator*() const { return cast<SpecificDecl>(*Current); } 1346d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan value_type operator->() const { return cast<SpecificDecl>(*Current); } 1347d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan 1348535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan filtered_decl_iterator& operator++() { 1349535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan ++Current; 1350535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan SkipToNextDecl(); 1351535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan return *this; 1352d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan } 1353d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan 1354d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan filtered_decl_iterator operator++(int) { 1355d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan filtered_decl_iterator tmp(*this); 1356d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan ++(*this); 1357535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan return tmp; 1358535de5338c3a76bc75905694ac15731e3f0bfc8dzhanyong.wan } 1359d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan 1360d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan friend bool operator==(const filtered_decl_iterator& x, 1361d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan const filtered_decl_iterator& y) { 1362d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan return x.Current == y.Current; 1363d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan } 1364d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan 1365d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan friend bool operator!=(const filtered_decl_iterator& x, 1366d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan const filtered_decl_iterator& y) { 1367d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan return x.Current != y.Current; 1368d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan } 1369d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan }; 1370d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan 1371d05532bf391ba7f7d147a598e737788787b9a7d5zhanyong.wan /// @brief Add the declaration D into this context. 1372f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// 13734b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// This routine should be invoked when the declaration D has first 1374d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// been declared, to place D into the context where it was 1375d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// (lexically) defined. Every declaration must be added to one 1376d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// (and only one!) context, where it can be visited via 1377d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// [decls_begin(), decls_end()). Once a declaration has been added 1378d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// to its lexical context, the corresponding DeclContext owns the 1379d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// declaration. 1380f6d087b78d230d875bf5d8281112662795044680zhanyong.wan /// 1381d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// If D is also a NamedDecl, it will be made visible within its 1382d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// semantic context via makeDeclVisibleInContext. 1383d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan void addDecl(Decl *D); 1384f6d087b78d230d875bf5d8281112662795044680zhanyong.wan 1385d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// @brief Add the declaration D into this context, but suppress 1386d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// searches for external declarations with the same name. 1387d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// 1388d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// Although analogous in function to addDecl, this removes an 1389d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// important check. This is only useful if the Decl is being 1390d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// added in response to an external search; in all other cases, 1391f6d087b78d230d875bf5d8281112662795044680zhanyong.wan /// addDecl() is the right function to use. 1392d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// See the ASTImporter for use cases. 1393d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan void addDeclInternal(Decl *D); 1394f6d087b78d230d875bf5d8281112662795044680zhanyong.wan 1395d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// @brief Add the declaration D to this context without modifying 1396d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// any lookup tables. 1397d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// 1398d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// This is useful for some operations in dependent contexts where 1399d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// the semantic context might not be dependent; this basically 1400d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// only happens with friends. 1401d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan void addHiddenDecl(Decl *D); 1402d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan 1403f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com /// @brief Removes a declaration from this context. 1404f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com void removeDecl(Decl *D); 1405f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com 1406d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// lookup_iterator - An iterator that provides access to the results 1407d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// of looking up a name within this context. 1408d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan typedef NamedDecl **lookup_iterator; 1409d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan 1410d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// lookup_const_iterator - An iterator that provides non-mutable 1411d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// access to the results of lookup up a name within this context. 1412d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan typedef NamedDecl * const * lookup_const_iterator; 1413d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan 1414d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan typedef DeclContextLookupResult lookup_result; 1415d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan typedef DeclContextLookupConstResult lookup_const_result; 1416f0d7f455d0ba1b1da1891c3ee54961a162e8fbc4billydonahue@google.com 1417d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// lookup - Find the declarations (if any) with the given Name in 1418d541f0259d2f6857df769f581363f84e8c4b2899zhanyong.wan /// this context. Returns a range of iterators that contains all of 14194b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// the declarations with this name, with object, function, member, 14204b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// and enumerator names preceding any tag name. Note that this 14214b6829f0d28990dd645e16386eb226d0f10c8731shiqian /// routine will not look into parent contexts. 14224b6829f0d28990dd645e16386eb226d0f10c8731shiqian lookup_result lookup(DeclarationName Name); 14234b6829f0d28990dd645e16386eb226d0f10c8731shiqian lookup_const_result lookup(DeclarationName Name) const { 1424 return const_cast<DeclContext*>(this)->lookup(Name); 1425 } 1426 1427 /// \brief A simplistic name lookup mechanism that performs name lookup 1428 /// into this declaration context without consulting the external source. 1429 /// 1430 /// This function should almost never be used, because it subverts the 1431 /// usual relationship between a DeclContext and the external source. 1432 /// See the ASTImporter for the (few, but important) use cases. 1433 void localUncachedLookup(DeclarationName Name, 1434 SmallVectorImpl<NamedDecl *> &Results); 1435 1436 /// @brief Makes a declaration visible within this context. 1437 /// 1438 /// This routine makes the declaration D visible to name lookup 1439 /// within this context and, if this is a transparent context, 1440 /// within its parent contexts up to the first enclosing 1441 /// non-transparent context. Making a declaration visible within a 1442 /// context does not transfer ownership of a declaration, and a 1443 /// declaration can be visible in many contexts that aren't its 1444 /// lexical context. 1445 /// 1446 /// If D is a redeclaration of an existing declaration that is 1447 /// visible from this context, as determined by 1448 /// NamedDecl::declarationReplaces, the previous declaration will be 1449 /// replaced with D. 1450 void makeDeclVisibleInContext(NamedDecl *D); 1451 1452 /// all_lookups_iterator - An iterator that provides a view over the results 1453 /// of looking up every possible name. 1454 class all_lookups_iterator; 1455 1456 all_lookups_iterator lookups_begin() const; 1457 1458 all_lookups_iterator lookups_end() const; 1459 1460 /// udir_iterator - Iterates through the using-directives stored 1461 /// within this context. 1462 typedef UsingDirectiveDecl * const * udir_iterator; 1463 1464 typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; 1465 1466 udir_iterator_range getUsingDirectives() const; 1467 1468 udir_iterator using_directives_begin() const { 1469 return getUsingDirectives().first; 1470 } 1471 1472 udir_iterator using_directives_end() const { 1473 return getUsingDirectives().second; 1474 } 1475 1476 // These are all defined in DependentDiagnostic.h. 1477 class ddiag_iterator; 1478 inline ddiag_iterator ddiag_begin() const; 1479 inline ddiag_iterator ddiag_end() const; 1480 1481 // Low-level accessors 1482 1483 /// \brief Mark the lookup table as needing to be built. This should be 1484 /// used only if setHasExternalLexicalStorage() has been called on any 1485 /// decl context for which this is the primary context. 1486 void setMustBuildLookupTable() { 1487 LookupPtr.setInt(true); 1488 } 1489 1490 /// \brief Retrieve the internal representation of the lookup structure. 1491 /// This may omit some names if we are lazily building the structure. 1492 StoredDeclsMap *getLookupPtr() const { return LookupPtr.getPointer(); } 1493 1494 /// \brief Ensure the lookup structure is fully-built and return it. 1495 StoredDeclsMap *buildLookup(); 1496 1497 /// \brief Whether this DeclContext has external storage containing 1498 /// additional declarations that are lexically in this context. 1499 bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; } 1500 1501 /// \brief State whether this DeclContext has external storage for 1502 /// declarations lexically in this context. 1503 void setHasExternalLexicalStorage(bool ES = true) { 1504 ExternalLexicalStorage = ES; 1505 } 1506 1507 /// \brief Whether this DeclContext has external storage containing 1508 /// additional declarations that are visible in this context. 1509 bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; } 1510 1511 /// \brief State whether this DeclContext has external storage for 1512 /// declarations visible in this context. 1513 void setHasExternalVisibleStorage(bool ES = true) { 1514 ExternalVisibleStorage = ES; 1515 if (ES && LookupPtr.getPointer()) 1516 NeedToReconcileExternalVisibleStorage = true; 1517 } 1518 1519 /// \brief Determine whether the given declaration is stored in the list of 1520 /// declarations lexically within this context. 1521 bool isDeclInLexicalTraversal(const Decl *D) const { 1522 return D && (D->NextInContextAndBits.getPointer() || D == FirstDecl || 1523 D == LastDecl); 1524 } 1525 1526 static bool classof(const Decl *D); 1527 static bool classof(const DeclContext *D) { return true; } 1528 1529 LLVM_ATTRIBUTE_USED void dumpDeclContext() const; 1530 1531private: 1532 void reconcileExternalVisibleStorage(); 1533 void LoadLexicalDeclsFromExternalStorage() const; 1534 1535 /// @brief Makes a declaration visible within this context, but 1536 /// suppresses searches for external declarations with the same 1537 /// name. 1538 /// 1539 /// Analogous to makeDeclVisibleInContext, but for the exclusive 1540 /// use of addDeclInternal(). 1541 void makeDeclVisibleInContextInternal(NamedDecl *D); 1542 1543 friend class DependentDiagnostic; 1544 StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const; 1545 1546 void buildLookupImpl(DeclContext *DCtx); 1547 void makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal, 1548 bool Rediscoverable); 1549 void makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal); 1550}; 1551 1552inline bool Decl::isTemplateParameter() const { 1553 return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm || 1554 getKind() == TemplateTemplateParm; 1555} 1556 1557// Specialization selected when ToTy is not a known subclass of DeclContext. 1558template <class ToTy, 1559 bool IsKnownSubtype = ::llvm::is_base_of< DeclContext, ToTy>::value> 1560struct cast_convert_decl_context { 1561 static const ToTy *doit(const DeclContext *Val) { 1562 return static_cast<const ToTy*>(Decl::castFromDeclContext(Val)); 1563 } 1564 1565 static ToTy *doit(DeclContext *Val) { 1566 return static_cast<ToTy*>(Decl::castFromDeclContext(Val)); 1567 } 1568}; 1569 1570// Specialization selected when ToTy is a known subclass of DeclContext. 1571template <class ToTy> 1572struct cast_convert_decl_context<ToTy, true> { 1573 static const ToTy *doit(const DeclContext *Val) { 1574 return static_cast<const ToTy*>(Val); 1575 } 1576 1577 static ToTy *doit(DeclContext *Val) { 1578 return static_cast<ToTy*>(Val); 1579 } 1580}; 1581 1582 1583} // end clang. 1584 1585namespace llvm { 1586 1587/// isa<T>(DeclContext*) 1588template <typename To> 1589struct isa_impl<To, ::clang::DeclContext> { 1590 static bool doit(const ::clang::DeclContext &Val) { 1591 return To::classofKind(Val.getDeclKind()); 1592 } 1593}; 1594 1595/// cast<T>(DeclContext*) 1596template<class ToTy> 1597struct cast_convert_val<ToTy, 1598 const ::clang::DeclContext,const ::clang::DeclContext> { 1599 static const ToTy &doit(const ::clang::DeclContext &Val) { 1600 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 1601 } 1602}; 1603template<class ToTy> 1604struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> { 1605 static ToTy &doit(::clang::DeclContext &Val) { 1606 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); 1607 } 1608}; 1609template<class ToTy> 1610struct cast_convert_val<ToTy, 1611 const ::clang::DeclContext*, const ::clang::DeclContext*> { 1612 static const ToTy *doit(const ::clang::DeclContext *Val) { 1613 return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 1614 } 1615}; 1616template<class ToTy> 1617struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> { 1618 static ToTy *doit(::clang::DeclContext *Val) { 1619 return ::clang::cast_convert_decl_context<ToTy>::doit(Val); 1620 } 1621}; 1622 1623/// Implement cast_convert_val for Decl -> DeclContext conversions. 1624template<class FromTy> 1625struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 1626 static ::clang::DeclContext &doit(const FromTy &Val) { 1627 return *FromTy::castToDeclContext(&Val); 1628 } 1629}; 1630 1631template<class FromTy> 1632struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 1633 static ::clang::DeclContext *doit(const FromTy *Val) { 1634 return FromTy::castToDeclContext(Val); 1635 } 1636}; 1637 1638template<class FromTy> 1639struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 1640 static const ::clang::DeclContext &doit(const FromTy &Val) { 1641 return *FromTy::castToDeclContext(&Val); 1642 } 1643}; 1644 1645template<class FromTy> 1646struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 1647 static const ::clang::DeclContext *doit(const FromTy *Val) { 1648 return FromTy::castToDeclContext(Val); 1649 } 1650}; 1651 1652} // end namespace llvm 1653 1654#endif 1655