Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 1 | //===-- DeclBase.h - Base Classes for representing declarations -*- C++ -*-===// |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 10 | // This file defines the Decl and DeclContext interfaces. |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CLANG_AST_DECLBASE_H |
| 15 | #define LLVM_CLANG_AST_DECLBASE_H |
| 16 | |
| 17 | #include "clang/AST/Attr.h" |
| 18 | #include "clang/AST/Type.h" |
John McCall | ad2b804 | 2010-01-18 23:21:37 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Specifiers.h" |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 20 | #include "llvm/Support/PrettyStackTrace.h" |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/PointerUnion.h" |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 22 | |
| 23 | namespace clang { |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 24 | class DeclContext; |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 25 | class TranslationUnitDecl; |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 26 | class NamespaceDecl; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 27 | class UsingDirectiveDecl; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 28 | class NamedDecl; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 29 | class FunctionDecl; |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 30 | class CXXRecordDecl; |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 31 | class EnumDecl; |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 32 | class ObjCMethodDecl; |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 33 | class ObjCContainerDecl; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 34 | class ObjCInterfaceDecl; |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 35 | class ObjCCategoryDecl; |
| 36 | class ObjCProtocolDecl; |
| 37 | class ObjCImplementationDecl; |
| 38 | class ObjCCategoryImplDecl; |
Argyrios Kyrtzidis | bfb498d | 2009-07-17 01:19:49 +0000 | [diff] [blame] | 39 | class ObjCImplDecl; |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 40 | class LinkageSpecDecl; |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 41 | class BlockDecl; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 42 | class DeclarationName; |
Ted Kremenek | eaab206 | 2009-03-12 18:33:24 +0000 | [diff] [blame] | 43 | class CompoundStmt; |
John McCall | 0c01d18 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 44 | class StoredDeclsMap; |
| 45 | class DependentDiagnostic; |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 46 | class ASTMutationListener; |
Chris Lattner | 0eda3b3 | 2009-03-29 04:32:54 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | namespace llvm { |
| 50 | // DeclContext* is only 4-byte aligned on 32-bit systems. |
| 51 | template<> |
| 52 | class PointerLikeTypeTraits<clang::DeclContext*> { |
| 53 | typedef clang::DeclContext* PT; |
| 54 | public: |
| 55 | static inline void *getAsVoidPointer(PT P) { return P; } |
| 56 | static inline PT getFromVoidPointer(void *P) { |
| 57 | return static_cast<PT>(P); |
| 58 | } |
| 59 | enum { NumLowBitsAvailable = 2 }; |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | namespace clang { |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 64 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 65 | /// \brief Captures the result of checking the availability of a |
| 66 | /// declaration. |
| 67 | enum AvailabilityResult { |
| 68 | AR_Available = 0, |
| 69 | AR_NotYetIntroduced, |
| 70 | AR_Deprecated, |
| 71 | AR_Unavailable |
| 72 | }; |
| 73 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 74 | /// Decl - This represents one declaration (or definition), e.g. a variable, |
| 75 | /// typedef, function, struct, etc. |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 76 | /// |
| 77 | class Decl { |
| 78 | public: |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 79 | /// \brief Lists the kind of concrete classes of Decl. |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 80 | enum Kind { |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 81 | #define DECL(DERIVED, BASE) DERIVED, |
| 82 | #define ABSTRACT_DECL(DECL) |
| 83 | #define DECL_RANGE(BASE, START, END) \ |
| 84 | first##BASE = START, last##BASE = END, |
| 85 | #define LAST_DECL_RANGE(BASE, START, END) \ |
| 86 | first##BASE = START, last##BASE = END |
| 87 | #include "clang/AST/DeclNodes.inc" |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 90 | /// \brief A placeholder type used to construct an empty shell of a |
| 91 | /// decl-derived type that will be filled in later (e.g., by some |
| 92 | /// deserialization method). |
| 93 | struct EmptyShell { }; |
| 94 | |
John McCall | 0d6b164 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 95 | /// IdentifierNamespace - The different namespaces in which |
| 96 | /// declarations may appear. According to C99 6.2.3, there are |
| 97 | /// four namespaces, labels, tags, members and ordinary |
| 98 | /// identifiers. C++ describes lookup completely differently: |
| 99 | /// certain lookups merely "ignore" certain kinds of declarations, |
| 100 | /// usually based on whether the declaration is of a type, etc. |
| 101 | /// |
| 102 | /// These are meant as bitmasks, so that searches in |
| 103 | /// C++ can look into the "tag" namespace during ordinary lookup. |
| 104 | /// |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 105 | /// Decl currently provides 15 bits of IDNS bits. |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 106 | enum IdentifierNamespace { |
John McCall | 0d6b164 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 107 | /// Labels, declared with 'x:' and referenced with 'goto x'. |
| 108 | IDNS_Label = 0x0001, |
| 109 | |
| 110 | /// Tags, declared with 'struct foo;' and referenced with |
| 111 | /// 'struct foo'. All tags are also types. This is what |
| 112 | /// elaborated-type-specifiers look for in C. |
| 113 | IDNS_Tag = 0x0002, |
| 114 | |
| 115 | /// Types, declared with 'struct foo', typedefs, etc. |
| 116 | /// This is what elaborated-type-specifiers look for in C++, |
| 117 | /// but note that it's ill-formed to find a non-tag. |
| 118 | IDNS_Type = 0x0004, |
| 119 | |
| 120 | /// Members, declared with object declarations within tag |
| 121 | /// definitions. In C, these can only be found by "qualified" |
| 122 | /// lookup in member expressions. In C++, they're found by |
| 123 | /// normal lookup. |
| 124 | IDNS_Member = 0x0008, |
| 125 | |
| 126 | /// Namespaces, declared with 'namespace foo {}'. |
| 127 | /// Lookup for nested-name-specifiers find these. |
| 128 | IDNS_Namespace = 0x0010, |
| 129 | |
| 130 | /// Ordinary names. In C, everything that's not a label, tag, |
| 131 | /// or member ends up here. |
| 132 | IDNS_Ordinary = 0x0020, |
| 133 | |
| 134 | /// Objective C @protocol. |
| 135 | IDNS_ObjCProtocol = 0x0040, |
| 136 | |
| 137 | /// This declaration is a friend function. A friend function |
| 138 | /// declaration is always in this namespace but may also be in |
| 139 | /// IDNS_Ordinary if it was previously declared. |
| 140 | IDNS_OrdinaryFriend = 0x0080, |
| 141 | |
| 142 | /// This declaration is a friend class. A friend class |
| 143 | /// declaration is always in this namespace but may also be in |
| 144 | /// IDNS_Tag|IDNS_Type if it was previously declared. |
| 145 | IDNS_TagFriend = 0x0100, |
| 146 | |
| 147 | /// This declaration is a using declaration. A using declaration |
| 148 | /// *introduces* a number of other declarations into the current |
| 149 | /// scope, and those declarations use the IDNS of their targets, |
| 150 | /// but the actual using declarations go in this namespace. |
John McCall | 76d3264 | 2010-04-24 01:30:58 +0000 | [diff] [blame] | 151 | IDNS_Using = 0x0200, |
| 152 | |
| 153 | /// This declaration is a C++ operator declared in a non-class |
| 154 | /// context. All such operators are also in IDNS_Ordinary. |
| 155 | /// C++ lexical operator lookup looks for these. |
| 156 | IDNS_NonMemberOperator = 0x0400 |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 157 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
John McCall | 09e2c52 | 2011-05-01 03:04:29 +0000 | [diff] [blame] | 159 | /// ObjCDeclQualifier - 'Qualifiers' written next to the return and |
| 160 | /// parameter types in method declarations. Other than remembering |
| 161 | /// them and mangling them into the method's signature string, these |
| 162 | /// are ignored by the compiler; they are consumed by certain |
| 163 | /// remote-messaging frameworks. |
| 164 | /// |
| 165 | /// in, inout, and out are mutually exclusive and apply only to |
| 166 | /// method parameters. bycopy and byref are mutually exclusive and |
| 167 | /// apply only to method parameters (?). oneway applies only to |
| 168 | /// results. All of these expect their corresponding parameter to |
| 169 | /// have a particular type. None of this is currently enforced by |
| 170 | /// clang. |
| 171 | /// |
| 172 | /// This should be kept in sync with ObjCDeclSpec::ObjCDeclQualifier. |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 173 | enum ObjCDeclQualifier { |
| 174 | OBJC_TQ_None = 0x0, |
| 175 | OBJC_TQ_In = 0x1, |
| 176 | OBJC_TQ_Inout = 0x2, |
| 177 | OBJC_TQ_Out = 0x4, |
| 178 | OBJC_TQ_Bycopy = 0x8, |
| 179 | OBJC_TQ_Byref = 0x10, |
| 180 | OBJC_TQ_Oneway = 0x20 |
| 181 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 182 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 183 | private: |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 184 | /// NextDeclInContext - The next declaration within the same lexical |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 185 | /// DeclContext. These pointers form the linked list that is |
| 186 | /// traversed via DeclContext's decls_begin()/decls_end(). |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 187 | Decl *NextDeclInContext; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 188 | |
| 189 | friend class DeclContext; |
| 190 | |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 191 | struct MultipleDC { |
| 192 | DeclContext *SemanticDC; |
| 193 | DeclContext *LexicalDC; |
| 194 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
| 196 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 197 | /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. |
| 198 | /// For declarations that don't contain C++ scope specifiers, it contains |
| 199 | /// the DeclContext where the Decl was declared. |
| 200 | /// For declarations with C++ scope specifiers, it contains a MultipleDC* |
| 201 | /// with the context where it semantically belongs (SemanticDC) and the |
| 202 | /// context where it was lexically declared (LexicalDC). |
| 203 | /// e.g.: |
| 204 | /// |
| 205 | /// namespace A { |
| 206 | /// void f(); // SemanticDC == LexicalDC == 'namespace A' |
| 207 | /// } |
| 208 | /// void A::f(); // SemanticDC == namespace 'A' |
| 209 | /// // LexicalDC == global namespace |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 210 | llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 211 | |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 212 | inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } |
| 213 | inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 214 | inline MultipleDC *getMultipleDC() const { |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 215 | return DeclCtx.get<MultipleDC*>(); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 216 | } |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 217 | inline DeclContext *getSemanticDC() const { |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 218 | return DeclCtx.get<DeclContext*>(); |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 219 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 220 | |
Douglas Gregor | 381d34e | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 221 | /// Loc - The location of this decl. |
Daniel Dunbar | 39d7650 | 2009-03-04 02:26:41 +0000 | [diff] [blame] | 222 | SourceLocation Loc; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 223 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 224 | /// DeclKind - This indicates which class this is. |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 225 | unsigned DeclKind : 8; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 226 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 227 | /// InvalidDecl - This indicates a semantic error occurred. |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 228 | unsigned InvalidDecl : 1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 229 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 230 | /// HasAttrs - This indicates whether the decl has attributes or not. |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 231 | unsigned HasAttrs : 1; |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 232 | |
Douglas Gregor | 6b3945f | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 233 | /// Implicit - Whether this declaration was implicitly generated by |
| 234 | /// the implementation rather than explicitly written by the user. |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 235 | unsigned Implicit : 1; |
Douglas Gregor | 6b3945f | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 236 | |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 237 | /// \brief Whether this declaration was "used", meaning that a definition is |
| 238 | /// required. |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 239 | unsigned Used : 1; |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 240 | |
Argyrios Kyrtzidis | 6b6b42a | 2011-04-19 19:51:10 +0000 | [diff] [blame] | 241 | /// \brief Whether this declaration was "referenced". |
| 242 | /// The difference with 'Used' is whether the reference appears in a |
| 243 | /// evaluated context or not, e.g. functions used in uninstantiated templates |
| 244 | /// are regarded as "referenced" but not "used". |
| 245 | unsigned Referenced : 1; |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 246 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 247 | protected: |
Douglas Gregor | 7d1d49d | 2009-10-16 20:01:17 +0000 | [diff] [blame] | 248 | /// Access - Used by C++ decls for the access specifier. |
| 249 | // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum |
| 250 | unsigned Access : 2; |
| 251 | friend class CXXClassMemberWrapper; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 252 | |
Douglas Gregor | 08e0bc1 | 2011-09-10 00:09:20 +0000 | [diff] [blame] | 253 | /// \brief Whether this declaration was loaded from an AST file. |
| 254 | unsigned FromASTFile : 1; |
| 255 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 256 | /// ChangedAfterLoad - if this declaration has changed since being loaded |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 257 | unsigned ChangedAfterLoad : 1; |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 258 | |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 259 | /// \brief Whether this declaration is private to the module in which it was |
| 260 | /// defined. |
| 261 | unsigned ModulePrivate : 1; |
| 262 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 263 | /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. |
Douglas Gregor | 381d34e | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 264 | unsigned IdentifierNamespace : 12; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | |
Douglas Gregor | 381d34e | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 266 | /// \brief Whether the \c CachedLinkage field is active. |
| 267 | /// |
| 268 | /// This field is only valid for NamedDecls subclasses. |
| 269 | mutable unsigned HasCachedLinkage : 1; |
| 270 | |
| 271 | /// \brief If \c HasCachedLinkage, the linkage of this declaration. |
| 272 | /// |
| 273 | /// This field is only valid for NamedDecls subclasses. |
| 274 | mutable unsigned CachedLinkage : 2; |
| 275 | |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 276 | friend class ASTDeclWriter; |
| 277 | friend class ASTDeclReader; |
| 278 | |
Douglas Gregor | 9cfbe48 | 2009-06-20 00:51:54 +0000 | [diff] [blame] | 279 | private: |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 280 | void CheckAccessDeclContext() const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 282 | protected: |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 283 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | Decl(Kind DK, DeclContext *DC, SourceLocation L) |
| 285 | : NextDeclInContext(0), DeclCtx(DC), |
Daniel Dunbar | 39d7650 | 2009-03-04 02:26:41 +0000 | [diff] [blame] | 286 | Loc(L), DeclKind(DK), InvalidDecl(0), |
Argyrios Kyrtzidis | 6b6b42a | 2011-04-19 19:51:10 +0000 | [diff] [blame] | 287 | HasAttrs(false), Implicit(false), Used(false), Referenced(false), |
Douglas Gregor | 08e0bc1 | 2011-09-10 00:09:20 +0000 | [diff] [blame] | 288 | Access(AS_none), FromASTFile(0), ChangedAfterLoad(false), |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 289 | ModulePrivate(0), |
Douglas Gregor | 381d34e | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 290 | IdentifierNamespace(getIdentifierNamespaceForKind(DK)), |
| 291 | HasCachedLinkage(0) |
| 292 | { |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 293 | if (Decl::CollectingStats()) add(DK); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 294 | } |
Sam Bishop | 1bb1963 | 2008-04-11 18:04:39 +0000 | [diff] [blame] | 295 | |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 296 | Decl(Kind DK, EmptyShell Empty) |
| 297 | : NextDeclInContext(0), DeclKind(DK), InvalidDecl(0), |
Argyrios Kyrtzidis | 6b6b42a | 2011-04-19 19:51:10 +0000 | [diff] [blame] | 298 | HasAttrs(false), Implicit(false), Used(false), Referenced(false), |
Douglas Gregor | 08e0bc1 | 2011-09-10 00:09:20 +0000 | [diff] [blame] | 299 | Access(AS_none), FromASTFile(0), ChangedAfterLoad(false), |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 300 | ModulePrivate(0), |
Douglas Gregor | 381d34e | 2010-12-06 18:36:25 +0000 | [diff] [blame] | 301 | IdentifierNamespace(getIdentifierNamespaceForKind(DK)), |
| 302 | HasCachedLinkage(0) |
| 303 | { |
Argyrios Kyrtzidis | 6764334 | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 304 | if (Decl::CollectingStats()) add(DK); |
| 305 | } |
| 306 | |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 307 | virtual ~Decl(); |
| 308 | |
Sam Bishop | 1bb1963 | 2008-04-11 18:04:39 +0000 | [diff] [blame] | 309 | public: |
Argyrios Kyrtzidis | 55d608c | 2009-06-20 08:09:14 +0000 | [diff] [blame] | 310 | |
| 311 | /// \brief Source range that this declaration covers. |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 312 | virtual SourceRange getSourceRange() const { |
| 313 | return SourceRange(getLocation(), getLocation()); |
| 314 | } |
Argyrios Kyrtzidis | 55d608c | 2009-06-20 08:09:14 +0000 | [diff] [blame] | 315 | SourceLocation getLocStart() const { return getSourceRange().getBegin(); } |
| 316 | SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } |
| 317 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 318 | SourceLocation getLocation() const { return Loc; } |
| 319 | void setLocation(SourceLocation L) { Loc = L; } |
| 320 | |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 321 | Kind getKind() const { return static_cast<Kind>(DeclKind); } |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 322 | const char *getDeclKindName() const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 324 | Decl *getNextDeclInContext() { return NextDeclInContext; } |
| 325 | const Decl *getNextDeclInContext() const { return NextDeclInContext; } |
Chris Lattner | 96f4468 | 2009-03-28 05:59:45 +0000 | [diff] [blame] | 326 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 327 | DeclContext *getDeclContext() { |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 328 | if (isInSemaDC()) |
| 329 | return getSemanticDC(); |
| 330 | return getMultipleDC()->SemanticDC; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 331 | } |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 332 | const DeclContext *getDeclContext() const { |
| 333 | return const_cast<Decl*>(this)->getDeclContext(); |
| 334 | } |
Argyrios Kyrtzidis | 3708b3d | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 335 | |
John McCall | aab9e31 | 2011-02-22 22:25:23 +0000 | [diff] [blame] | 336 | /// Finds the innermost non-closure context of this declaration. |
| 337 | /// That is, walk out the DeclContext chain, skipping any blocks. |
| 338 | DeclContext *getNonClosureContext(); |
| 339 | const DeclContext *getNonClosureContext() const { |
| 340 | return const_cast<Decl*>(this)->getNonClosureContext(); |
| 341 | } |
| 342 | |
Argyrios Kyrtzidis | 3708b3d | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 343 | TranslationUnitDecl *getTranslationUnitDecl(); |
| 344 | const TranslationUnitDecl *getTranslationUnitDecl() const { |
| 345 | return const_cast<Decl*>(this)->getTranslationUnitDecl(); |
| 346 | } |
| 347 | |
John McCall | 9aeed32 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 348 | bool isInAnonymousNamespace() const; |
| 349 | |
Argyrios Kyrtzidis | 3708b3d | 2009-06-29 17:38:40 +0000 | [diff] [blame] | 350 | ASTContext &getASTContext() const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 351 | |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 352 | void setAccess(AccessSpecifier AS) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 353 | Access = AS; |
Douglas Gregor | 3a1c36c | 2010-12-02 00:22:25 +0000 | [diff] [blame] | 354 | #ifndef NDEBUG |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 355 | CheckAccessDeclContext(); |
Douglas Gregor | 3a1c36c | 2010-12-02 00:22:25 +0000 | [diff] [blame] | 356 | #endif |
Anders Carlsson | b8547e8 | 2009-03-25 20:19:57 +0000 | [diff] [blame] | 357 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 358 | |
| 359 | AccessSpecifier getAccess() const { |
Douglas Gregor | 3a1c36c | 2010-12-02 00:22:25 +0000 | [diff] [blame] | 360 | #ifndef NDEBUG |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 361 | CheckAccessDeclContext(); |
Douglas Gregor | 3a1c36c | 2010-12-02 00:22:25 +0000 | [diff] [blame] | 362 | #endif |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | return AccessSpecifier(Access); |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 364 | } |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 365 | |
Chris Lattner | 76a642f | 2009-02-15 22:43:40 +0000 | [diff] [blame] | 366 | bool hasAttrs() const { return HasAttrs; } |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 367 | void setAttrs(const AttrVec& Attrs); |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 368 | AttrVec &getAttrs() { |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 369 | return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs()); |
Chris Lattner | 81abbdd | 2009-03-21 06:27:31 +0000 | [diff] [blame] | 370 | } |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 371 | const AttrVec &getAttrs() const; |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 372 | void swapAttrs(Decl *D); |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 373 | void dropAttrs(); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 374 | |
Douglas Gregor | b5f35ba | 2010-12-06 17:49:01 +0000 | [diff] [blame] | 375 | void addAttr(Attr *A) { |
| 376 | if (hasAttrs()) |
| 377 | getAttrs().push_back(A); |
| 378 | else |
| 379 | setAttrs(AttrVec(1, A)); |
| 380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 382 | typedef AttrVec::const_iterator attr_iterator; |
| 383 | |
| 384 | // FIXME: Do not rely on iterators having comparable singular values. |
| 385 | // Note that this should error out if they do not. |
| 386 | attr_iterator attr_begin() const { |
| 387 | return hasAttrs() ? getAttrs().begin() : 0; |
| 388 | } |
| 389 | attr_iterator attr_end() const { |
| 390 | return hasAttrs() ? getAttrs().end() : 0; |
| 391 | } |
Fariborz Jahanian | c3ca14d | 2011-06-23 17:50:10 +0000 | [diff] [blame] | 392 | |
| 393 | template <typename T> |
Fariborz Jahanian | 8cf0f52 | 2011-06-23 20:24:38 +0000 | [diff] [blame] | 394 | void dropAttr() { |
| 395 | if (!HasAttrs) return; |
| 396 | |
| 397 | AttrVec &Attrs = getAttrs(); |
| 398 | for (unsigned i = 0, e = Attrs.size(); i != e; /* in loop */) { |
| 399 | if (isa<T>(Attrs[i])) { |
| 400 | Attrs.erase(Attrs.begin() + i); |
| 401 | --e; |
| 402 | } |
| 403 | else |
| 404 | ++i; |
| 405 | } |
| 406 | if (Attrs.empty()) |
| 407 | HasAttrs = false; |
| 408 | } |
| 409 | |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 410 | template <typename T> |
| 411 | specific_attr_iterator<T> specific_attr_begin() const { |
| 412 | return specific_attr_iterator<T>(attr_begin()); |
| 413 | } |
| 414 | template <typename T> |
| 415 | specific_attr_iterator<T> specific_attr_end() const { |
| 416 | return specific_attr_iterator<T>(attr_end()); |
| 417 | } |
| 418 | |
| 419 | template<typename T> T *getAttr() const { |
| 420 | return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : 0; |
| 421 | } |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 422 | template<typename T> bool hasAttr() const { |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 423 | return hasAttrs() && hasSpecificAttr<T>(getAttrs()); |
| 424 | } |
| 425 | |
| 426 | /// getMaxAlignment - return the maximum alignment specified by attributes |
| 427 | /// on this decl, 0 if there are none. |
| 428 | unsigned getMaxAlignment() const { |
| 429 | return hasAttrs() ? getMaxAttrAlignment(getAttrs(), getASTContext()) : 0; |
Chris Lattner | 115cafc | 2009-04-12 20:07:59 +0000 | [diff] [blame] | 430 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 431 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 432 | /// setInvalidDecl - Indicates the Decl had a semantic error. This |
| 433 | /// allows for graceful error recovery. |
Douglas Gregor | 4273857 | 2010-03-05 00:26:45 +0000 | [diff] [blame] | 434 | void setInvalidDecl(bool Invalid = true); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 435 | bool isInvalidDecl() const { return (bool) InvalidDecl; } |
Douglas Gregor | 6b3945f | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 436 | |
| 437 | /// isImplicit - Indicates whether the declaration was implicitly |
| 438 | /// generated by the implementation. If false, this declaration |
| 439 | /// was written explicitly in the source code. |
| 440 | bool isImplicit() const { return Implicit; } |
| 441 | void setImplicit(bool I = true) { Implicit = I; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 442 | |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 443 | /// \brief Whether this declaration was used, meaning that a definition |
| 444 | /// is required. |
Douglas Gregor | c070cc6 | 2010-06-17 23:14:26 +0000 | [diff] [blame] | 445 | /// |
| 446 | /// \param CheckUsedAttr When true, also consider the "used" attribute |
| 447 | /// (in addition to the "used" bit set by \c setUsed()) when determining |
| 448 | /// whether the function is used. |
| 449 | bool isUsed(bool CheckUsedAttr = true) const; |
Sean Hunt | cf807c4 | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 450 | |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 451 | void setUsed(bool U = true) { Used = U; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 452 | |
Argyrios Kyrtzidis | 6b6b42a | 2011-04-19 19:51:10 +0000 | [diff] [blame] | 453 | /// \brief Whether this declaration was referenced. |
| 454 | bool isReferenced() const; |
| 455 | |
| 456 | void setReferenced(bool R = true) { Referenced = R; } |
| 457 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 458 | /// \brief Determine the availability of the given declaration. |
| 459 | /// |
| 460 | /// This routine will determine the most restrictive availability of |
| 461 | /// the given declaration (e.g., preferring 'unavailable' to |
| 462 | /// 'deprecated'). |
| 463 | /// |
| 464 | /// \param Message If non-NULL and the result is not \c |
| 465 | /// AR_Available, will be set to a (possibly empty) message |
| 466 | /// describing why the declaration has not been introduced, is |
| 467 | /// deprecated, or is unavailable. |
| 468 | AvailabilityResult getAvailability(std::string *Message = 0) const; |
| 469 | |
| 470 | /// \brief Determine whether this declaration is marked 'deprecated'. |
| 471 | /// |
| 472 | /// \param Message If non-NULL and the declaration is deprecated, |
| 473 | /// this will be set to the message describing why the declaration |
| 474 | /// was deprecated (which may be empty). |
| 475 | bool isDeprecated(std::string *Message = 0) const { |
| 476 | return getAvailability(Message) == AR_Deprecated; |
| 477 | } |
| 478 | |
| 479 | /// \brief Determine whether this declaration is marked 'unavailable'. |
| 480 | /// |
| 481 | /// \param Message If non-NULL and the declaration is unavailable, |
| 482 | /// this will be set to the message describing why the declaration |
| 483 | /// was made unavailable (which may be empty). |
| 484 | bool isUnavailable(std::string *Message = 0) const { |
| 485 | return getAvailability(Message) == AR_Unavailable; |
| 486 | } |
| 487 | |
| 488 | /// \brief Determine whether this is a weak-imported symbol. |
| 489 | /// |
| 490 | /// Weak-imported symbols are typically marked with the |
Eli Friedman | 7f3ad23 | 2011-03-28 02:00:21 +0000 | [diff] [blame] | 491 | /// 'weak_import' attribute, but may also be marked with an |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 492 | /// 'availability' attribute where we're targing a platform prior to |
| 493 | /// the introduction of this feature. |
| 494 | bool isWeakImported() const; |
| 495 | |
| 496 | /// \brief Determines whether this symbol can be weak-imported, |
| 497 | /// e.g., whether it would be well-formed to add the weak_import |
| 498 | /// attribute. |
| 499 | /// |
| 500 | /// \param IsDefinition Set to \c true to indicate that this |
| 501 | /// declaration cannot be weak-imported because it has a definition. |
| 502 | bool canBeWeakImported(bool &IsDefinition) const; |
| 503 | |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 504 | /// \brief Determine whether this declaration came from an AST file (such as |
| 505 | /// a precompiled header or module) rather than having been parsed. |
Douglas Gregor | 08e0bc1 | 2011-09-10 00:09:20 +0000 | [diff] [blame] | 506 | bool isFromASTFile() const { return FromASTFile; } |
Douglas Gregor | 919814d | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 507 | |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 508 | /// \brief Query whether this declaration was changed in a significant way |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 509 | /// since being loaded from an AST file. |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 510 | /// |
| 511 | /// In an epic violation of layering, what is "significant" is entirely |
Sebastian Redl | 3397c55 | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 512 | /// up to the serialization system, but implemented in AST and Sema. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 513 | bool isChangedSinceDeserialization() const { return ChangedAfterLoad; } |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 514 | |
| 515 | /// \brief Mark this declaration as having changed since deserialization, or |
| 516 | /// reset the flag. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 517 | void setChangedSinceDeserialization(bool Changed) { |
| 518 | ChangedAfterLoad = Changed; |
| 519 | } |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 520 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 521 | unsigned getIdentifierNamespace() const { |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 522 | return IdentifierNamespace; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 523 | } |
Chris Lattner | d62fdc4 | 2009-01-06 07:16:40 +0000 | [diff] [blame] | 524 | bool isInIdentifierNamespace(unsigned NS) const { |
| 525 | return getIdentifierNamespace() & NS; |
| 526 | } |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 527 | static unsigned getIdentifierNamespaceForKind(Kind DK); |
| 528 | |
John McCall | 0d6b164 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 529 | bool hasTagIdentifierNamespace() const { |
| 530 | return isTagIdentifierNamespace(getIdentifierNamespace()); |
| 531 | } |
| 532 | static bool isTagIdentifierNamespace(unsigned NS) { |
| 533 | // TagDecls have Tag and Type set and may also have TagFriend. |
| 534 | return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type); |
| 535 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 537 | /// getLexicalDeclContext - The declaration context where this Decl was |
| 538 | /// lexically declared (LexicalDC). May be different from |
| 539 | /// getDeclContext() (SemanticDC). |
| 540 | /// e.g.: |
| 541 | /// |
| 542 | /// namespace A { |
| 543 | /// void f(); // SemanticDC == LexicalDC == 'namespace A' |
| 544 | /// } |
| 545 | /// void A::f(); // SemanticDC == namespace 'A' |
| 546 | /// // LexicalDC == global namespace |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 547 | DeclContext *getLexicalDeclContext() { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 548 | if (isInSemaDC()) |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 549 | return getSemanticDC(); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 550 | return getMultipleDC()->LexicalDC; |
| 551 | } |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 552 | const DeclContext *getLexicalDeclContext() const { |
| 553 | return const_cast<Decl*>(this)->getLexicalDeclContext(); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 554 | } |
Argyrios Kyrtzidis | f5cecfb | 2009-06-17 22:49:50 +0000 | [diff] [blame] | 555 | |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 556 | virtual bool isOutOfLine() const { |
| 557 | return getLexicalDeclContext() != getDeclContext(); |
| 558 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 559 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 560 | /// setDeclContext - Set both the semantic and lexical DeclContext |
| 561 | /// to DC. |
| 562 | void setDeclContext(DeclContext *DC); |
| 563 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 564 | void setLexicalDeclContext(DeclContext *DC); |
| 565 | |
Sebastian Redl | 7a126a4 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 566 | /// isDefinedOutsideFunctionOrMethod - This predicate returns true if this |
| 567 | /// scoped decl is defined outside the current function or method. This is |
| 568 | /// roughly global variables and functions, but also handles enums (which |
| 569 | /// could be defined inside or outside a function etc). |
Argyrios Kyrtzidis | c8680f4 | 2011-09-28 02:45:33 +0000 | [diff] [blame^] | 570 | bool isDefinedOutsideFunctionOrMethod() const { |
| 571 | return getParentFunctionOrMethod() == 0; |
| 572 | } |
| 573 | |
| 574 | /// \brief If this decl is defined inside a function/method/block it returns |
| 575 | /// the corresponding DeclContext, otherwise it returns null. |
| 576 | const DeclContext *getParentFunctionOrMethod() const; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 577 | |
Argyrios Kyrtzidis | b57a4fe | 2009-07-18 00:34:07 +0000 | [diff] [blame] | 578 | /// \brief Retrieves the "canonical" declaration of the given declaration. |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 579 | virtual Decl *getCanonicalDecl() { return this; } |
Argyrios Kyrtzidis | b57a4fe | 2009-07-18 00:34:07 +0000 | [diff] [blame] | 580 | const Decl *getCanonicalDecl() const { |
| 581 | return const_cast<Decl*>(this)->getCanonicalDecl(); |
| 582 | } |
Argyrios Kyrtzidis | fc7e2a8 | 2009-07-05 22:21:56 +0000 | [diff] [blame] | 583 | |
Argyrios Kyrtzidis | ac4e379 | 2009-07-18 08:50:48 +0000 | [diff] [blame] | 584 | /// \brief Whether this particular Decl is a canonical one. |
Argyrios Kyrtzidis | b57a4fe | 2009-07-18 00:34:07 +0000 | [diff] [blame] | 585 | bool isCanonicalDecl() const { return getCanonicalDecl() == this; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 586 | |
Argyrios Kyrtzidis | 1e4bc09 | 2009-07-18 08:50:35 +0000 | [diff] [blame] | 587 | protected: |
| 588 | /// \brief Returns the next redeclaration or itself if this is the only decl. |
| 589 | /// |
| 590 | /// Decl subclasses that can be redeclared should override this method so that |
| 591 | /// Decl::redecl_iterator can iterate over them. |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 592 | virtual Decl *getNextRedeclaration() { return this; } |
Argyrios Kyrtzidis | 1e4bc09 | 2009-07-18 08:50:35 +0000 | [diff] [blame] | 593 | |
| 594 | public: |
| 595 | /// \brief Iterates through all the redeclarations of the same decl. |
| 596 | class redecl_iterator { |
| 597 | /// Current - The current declaration. |
| 598 | Decl *Current; |
| 599 | Decl *Starter; |
| 600 | |
| 601 | public: |
| 602 | typedef Decl* value_type; |
| 603 | typedef Decl* reference; |
| 604 | typedef Decl* pointer; |
| 605 | typedef std::forward_iterator_tag iterator_category; |
| 606 | typedef std::ptrdiff_t difference_type; |
| 607 | |
| 608 | redecl_iterator() : Current(0) { } |
| 609 | explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { } |
| 610 | |
| 611 | reference operator*() const { return Current; } |
| 612 | pointer operator->() const { return Current; } |
| 613 | |
| 614 | redecl_iterator& operator++() { |
| 615 | assert(Current && "Advancing while iterator has reached end"); |
| 616 | // Get either previous decl or latest decl. |
| 617 | Decl *Next = Current->getNextRedeclaration(); |
Argyrios Kyrtzidis | 22cbd2b | 2009-07-21 00:06:27 +0000 | [diff] [blame] | 618 | assert(Next && "Should return next redeclaration or itself, never null!"); |
Argyrios Kyrtzidis | 1e4bc09 | 2009-07-18 08:50:35 +0000 | [diff] [blame] | 619 | Current = (Next != Starter ? Next : 0); |
| 620 | return *this; |
| 621 | } |
| 622 | |
| 623 | redecl_iterator operator++(int) { |
| 624 | redecl_iterator tmp(*this); |
| 625 | ++(*this); |
| 626 | return tmp; |
| 627 | } |
| 628 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 629 | friend bool operator==(redecl_iterator x, redecl_iterator y) { |
Argyrios Kyrtzidis | 1e4bc09 | 2009-07-18 08:50:35 +0000 | [diff] [blame] | 630 | return x.Current == y.Current; |
| 631 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 632 | friend bool operator!=(redecl_iterator x, redecl_iterator y) { |
Argyrios Kyrtzidis | 1e4bc09 | 2009-07-18 08:50:35 +0000 | [diff] [blame] | 633 | return x.Current != y.Current; |
| 634 | } |
| 635 | }; |
| 636 | |
| 637 | /// \brief Returns iterator for all the redeclarations of the same decl. |
| 638 | /// It will iterate at least once (when this decl is the only one). |
| 639 | redecl_iterator redecls_begin() const { |
| 640 | return redecl_iterator(const_cast<Decl*>(this)); |
| 641 | } |
| 642 | redecl_iterator redecls_end() const { return redecl_iterator(); } |
Argyrios Kyrtzidis | fc7e2a8 | 2009-07-05 22:21:56 +0000 | [diff] [blame] | 643 | |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 644 | /// getBody - If this Decl represents a declaration for a body of code, |
| 645 | /// such as a function or method definition, this method returns the |
| 646 | /// top-level Stmt* of that body. Otherwise this method returns null. |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 647 | virtual Stmt* getBody() const { return 0; } |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 648 | |
Argyrios Kyrtzidis | 06a54a3 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 649 | /// \brief Returns true if this Decl represents a declaration for a body of |
| 650 | /// code, such as a function or method definition. |
Douglas Gregor | da2142f | 2011-02-19 18:51:44 +0000 | [diff] [blame] | 651 | virtual bool hasBody() const { return getBody() != 0; } |
Argyrios Kyrtzidis | 06a54a3 | 2010-07-07 11:31:19 +0000 | [diff] [blame] | 652 | |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 653 | /// getBodyRBrace - Gets the right brace of the body, if a body exists. |
| 654 | /// This works whether the body is a CompoundStmt or a CXXTryStmt. |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 655 | SourceLocation getBodyRBrace() const; |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 656 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 657 | // global temp stats (until we have a per-module visitor) |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 658 | static void add(Kind k); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 659 | static bool CollectingStats(bool Enable = false); |
| 660 | static void PrintStats(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 661 | |
Anders Carlsson | 67e3320 | 2009-06-13 00:08:58 +0000 | [diff] [blame] | 662 | /// isTemplateParameter - Determines whether this declaration is a |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 663 | /// template parameter. |
| 664 | bool isTemplateParameter() const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 665 | |
Anders Carlsson | 67e3320 | 2009-06-13 00:08:58 +0000 | [diff] [blame] | 666 | /// isTemplateParameter - Determines whether this declaration is a |
| 667 | /// template parameter pack. |
| 668 | bool isTemplateParameterPack() const; |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 669 | |
Douglas Gregor | 1fe85ea | 2011-01-05 21:11:38 +0000 | [diff] [blame] | 670 | /// \brief Whether this declaration is a parameter pack. |
| 671 | bool isParameterPack() const; |
| 672 | |
Caitlin Sadowski | ed9d84a | 2011-09-08 17:42:31 +0000 | [diff] [blame] | 673 | /// \brief returns true if this declaration is a template |
| 674 | bool isTemplateDecl() const; |
| 675 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 676 | /// \brief Whether this declaration is a function or function template. |
| 677 | bool isFunctionOrFunctionTemplate() const; |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 678 | |
| 679 | /// \brief Changes the namespace of this declaration to reflect that it's |
| 680 | /// the object of a friend declaration. |
| 681 | /// |
| 682 | /// These declarations appear in the lexical context of the friending |
| 683 | /// class, but in the semantic context of the actual entity. This property |
| 684 | /// applies only to a specific decl object; other redeclarations of the |
| 685 | /// same entity may not (and probably don't) share this property. |
| 686 | void setObjectOfFriendDecl(bool PreviouslyDeclared) { |
| 687 | unsigned OldNS = IdentifierNamespace; |
John McCall | b0cb022 | 2010-03-27 05:57:59 +0000 | [diff] [blame] | 688 | assert((OldNS & (IDNS_Tag | IDNS_Ordinary | |
| 689 | IDNS_TagFriend | IDNS_OrdinaryFriend)) && |
| 690 | "namespace includes neither ordinary nor tag"); |
John McCall | 0d6b164 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 691 | assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type | |
John McCall | b0cb022 | 2010-03-27 05:57:59 +0000 | [diff] [blame] | 692 | IDNS_TagFriend | IDNS_OrdinaryFriend)) && |
| 693 | "namespace includes other than ordinary or tag"); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 694 | |
John McCall | b0cb022 | 2010-03-27 05:57:59 +0000 | [diff] [blame] | 695 | IdentifierNamespace = 0; |
| 696 | if (OldNS & (IDNS_Tag | IDNS_TagFriend)) { |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 697 | IdentifierNamespace |= IDNS_TagFriend; |
John McCall | 0d6b164 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 698 | if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Tag | IDNS_Type; |
John McCall | b0cb022 | 2010-03-27 05:57:59 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend)) { |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 702 | IdentifierNamespace |= IDNS_OrdinaryFriend; |
John McCall | b0cb022 | 2010-03-27 05:57:59 +0000 | [diff] [blame] | 703 | if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Ordinary; |
| 704 | } |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | enum FriendObjectKind { |
| 708 | FOK_None, // not a friend object |
| 709 | FOK_Declared, // a friend of a previously-declared entity |
| 710 | FOK_Undeclared // a friend of a previously-undeclared entity |
| 711 | }; |
| 712 | |
| 713 | /// \brief Determines whether this declaration is the object of a |
| 714 | /// friend declaration and, if so, what kind. |
| 715 | /// |
| 716 | /// There is currently no direct way to find the associated FriendDecl. |
| 717 | FriendObjectKind getFriendObjectKind() const { |
| 718 | unsigned mask |
| 719 | = (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend)); |
| 720 | if (!mask) return FOK_None; |
Anders Carlsson | 255d641 | 2009-09-13 23:59:13 +0000 | [diff] [blame] | 721 | return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? |
| 722 | FOK_Declared : FOK_Undeclared); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 723 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 724 | |
John McCall | 76d3264 | 2010-04-24 01:30:58 +0000 | [diff] [blame] | 725 | /// Specifies that this declaration is a C++ overloaded non-member. |
| 726 | void setNonMemberOperator() { |
| 727 | assert(getKind() == Function || getKind() == FunctionTemplate); |
| 728 | assert((IdentifierNamespace & IDNS_Ordinary) && |
| 729 | "visible non-member operators should be in ordinary namespace"); |
| 730 | IdentifierNamespace |= IDNS_NonMemberOperator; |
| 731 | } |
| 732 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 733 | // Implement isa/cast/dyncast/etc. |
| 734 | static bool classof(const Decl *) { return true; } |
John McCall | 80cd64a | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 735 | static bool classofKind(Kind K) { return true; } |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 736 | static DeclContext *castToDeclContext(const Decl *); |
| 737 | static Decl *castFromDeclContext(const DeclContext *); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 738 | |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 739 | void print(raw_ostream &Out, unsigned Indentation = 0, |
| 740 | bool PrintInstantiation = false) const; |
Chris Lattner | 8cc488f | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 741 | void print(raw_ostream &Out, const PrintingPolicy &Policy, |
Richard Trieu | 5cb3d69 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 742 | unsigned Indentation = 0, bool PrintInstantiation = false) const; |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 743 | static void printGroup(Decl** Begin, unsigned NumDecls, |
Chris Lattner | 8cc488f | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 744 | raw_ostream &Out, const PrintingPolicy &Policy, |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 745 | unsigned Indentation = 0); |
Anders Carlsson | f88df86 | 2009-09-26 21:58:53 +0000 | [diff] [blame] | 746 | void dump() const; |
John McCall | f351424 | 2010-11-24 11:21:45 +0000 | [diff] [blame] | 747 | void dumpXML() const; |
Chris Lattner | 8cc488f | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 748 | void dumpXML(raw_ostream &OS) const; |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 749 | |
Chris Lattner | 81abbdd | 2009-03-21 06:27:31 +0000 | [diff] [blame] | 750 | private: |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 751 | const Attr *getAttrsImpl() const; |
Chris Lattner | 81abbdd | 2009-03-21 06:27:31 +0000 | [diff] [blame] | 752 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 753 | protected: |
| 754 | ASTMutationListener *getASTMutationListener() const; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 755 | }; |
| 756 | |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 757 | /// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when |
| 758 | /// doing something to a specific decl. |
| 759 | class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { |
Daniel Dunbar | c523656 | 2009-11-21 09:05:59 +0000 | [diff] [blame] | 760 | const Decl *TheDecl; |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 761 | SourceLocation Loc; |
| 762 | SourceManager &SM; |
| 763 | const char *Message; |
| 764 | public: |
Daniel Dunbar | c523656 | 2009-11-21 09:05:59 +0000 | [diff] [blame] | 765 | PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L, |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 766 | SourceManager &sm, const char *Msg) |
| 767 | : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
Chris Lattner | 8cc488f | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 769 | virtual void print(raw_ostream &OS) const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 770 | }; |
| 771 | |
John McCall | 6d9496d | 2010-08-26 09:52:08 +0000 | [diff] [blame] | 772 | class DeclContextLookupResult |
| 773 | : public std::pair<NamedDecl**,NamedDecl**> { |
John McCall | ea31864 | 2010-08-26 09:15:37 +0000 | [diff] [blame] | 774 | public: |
John McCall | 6d9496d | 2010-08-26 09:52:08 +0000 | [diff] [blame] | 775 | DeclContextLookupResult(NamedDecl **I, NamedDecl **E) |
| 776 | : std::pair<NamedDecl**,NamedDecl**>(I, E) {} |
| 777 | DeclContextLookupResult() |
| 778 | : std::pair<NamedDecl**,NamedDecl**>() {} |
John McCall | ea31864 | 2010-08-26 09:15:37 +0000 | [diff] [blame] | 779 | |
John McCall | f29815a | 2010-08-26 10:20:09 +0000 | [diff] [blame] | 780 | using std::pair<NamedDecl**,NamedDecl**>::operator=; |
John McCall | ea31864 | 2010-08-26 09:15:37 +0000 | [diff] [blame] | 781 | }; |
| 782 | |
| 783 | class DeclContextLookupConstResult |
| 784 | : public std::pair<NamedDecl*const*, NamedDecl*const*> { |
| 785 | public: |
| 786 | DeclContextLookupConstResult(std::pair<NamedDecl**,NamedDecl**> R) |
John McCall | 6d9496d | 2010-08-26 09:52:08 +0000 | [diff] [blame] | 787 | : std::pair<NamedDecl*const*, NamedDecl*const*>(R) {} |
John McCall | ea31864 | 2010-08-26 09:15:37 +0000 | [diff] [blame] | 788 | DeclContextLookupConstResult(NamedDecl * const *I, NamedDecl * const *E) |
John McCall | 6d9496d | 2010-08-26 09:52:08 +0000 | [diff] [blame] | 789 | : std::pair<NamedDecl*const*, NamedDecl*const*>(I, E) {} |
| 790 | DeclContextLookupConstResult() |
| 791 | : std::pair<NamedDecl*const*, NamedDecl*const*>() {} |
John McCall | ea31864 | 2010-08-26 09:15:37 +0000 | [diff] [blame] | 792 | |
John McCall | f29815a | 2010-08-26 10:20:09 +0000 | [diff] [blame] | 793 | using std::pair<NamedDecl*const*,NamedDecl*const*>::operator=; |
John McCall | ea31864 | 2010-08-26 09:15:37 +0000 | [diff] [blame] | 794 | }; |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 795 | |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 796 | /// DeclContext - This is used only as base class of specific decl types that |
Argyrios Kyrtzidis | 1ad4dd7 | 2009-02-16 14:28:33 +0000 | [diff] [blame] | 797 | /// can act as declaration contexts. These decls are (only the top classes |
| 798 | /// that directly derive from DeclContext are mentioned, not their subclasses): |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 799 | /// |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 800 | /// TranslationUnitDecl |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 801 | /// NamespaceDecl |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 802 | /// FunctionDecl |
Argyrios Kyrtzidis | 1ad4dd7 | 2009-02-16 14:28:33 +0000 | [diff] [blame] | 803 | /// TagDecl |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 804 | /// ObjCMethodDecl |
Argyrios Kyrtzidis | 1ad4dd7 | 2009-02-16 14:28:33 +0000 | [diff] [blame] | 805 | /// ObjCContainerDecl |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 806 | /// LinkageSpecDecl |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 807 | /// BlockDecl |
Argyrios Kyrtzidis | 1ad4dd7 | 2009-02-16 14:28:33 +0000 | [diff] [blame] | 808 | /// |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 809 | class DeclContext { |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 810 | /// DeclKind - This indicates which class this is. |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 811 | unsigned DeclKind : 8; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 812 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 813 | /// \brief Whether this declaration context also has some external |
| 814 | /// storage that contains additional declarations that are lexically |
| 815 | /// part of this context. |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 816 | mutable unsigned ExternalLexicalStorage : 1; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 817 | |
| 818 | /// \brief Whether this declaration context also has some external |
| 819 | /// storage that contains additional declarations that are visible |
| 820 | /// in this context. |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 821 | mutable unsigned ExternalVisibleStorage : 1; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 822 | |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 823 | /// \brief Pointer to the data structure used to lookup declarations |
John McCall | 0c01d18 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 824 | /// within this context (or a DependentStoredDeclsMap if this is a |
| 825 | /// dependent context). |
| 826 | mutable StoredDeclsMap *LookupPtr; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 827 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 828 | protected: |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 829 | /// FirstDecl - The first declaration stored within this declaration |
| 830 | /// context. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 831 | mutable Decl *FirstDecl; |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 832 | |
| 833 | /// LastDecl - The last declaration stored within this declaration |
| 834 | /// context. FIXME: We could probably cache this value somewhere |
| 835 | /// outside of the DeclContext, to reduce the size of DeclContext by |
| 836 | /// another pointer. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 837 | mutable Decl *LastDecl; |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 838 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 839 | friend class ExternalASTSource; |
| 840 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 841 | /// \brief Build up a chain of declarations. |
| 842 | /// |
| 843 | /// \returns the first/last pair of declarations. |
| 844 | static std::pair<Decl *, Decl *> |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 845 | BuildDeclChain(const SmallVectorImpl<Decl*> &Decls); |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 846 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 847 | DeclContext(Decl::Kind K) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 848 | : DeclKind(K), ExternalLexicalStorage(false), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 849 | ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0), |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 850 | LastDecl(0) { } |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 851 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 852 | public: |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 853 | ~DeclContext(); |
| 854 | |
Argyrios Kyrtzidis | 9b9ca01 | 2009-01-13 13:11:58 +0000 | [diff] [blame] | 855 | Decl::Kind getDeclKind() const { |
John McCall | 35043e5 | 2010-10-19 05:43:52 +0000 | [diff] [blame] | 856 | return static_cast<Decl::Kind>(DeclKind); |
Argyrios Kyrtzidis | 9b9ca01 | 2009-01-13 13:11:58 +0000 | [diff] [blame] | 857 | } |
Steve Naroff | 0a47393 | 2009-01-20 19:53:53 +0000 | [diff] [blame] | 858 | const char *getDeclKindName() const; |
Argyrios Kyrtzidis | 9b9ca01 | 2009-01-13 13:11:58 +0000 | [diff] [blame] | 859 | |
Argyrios Kyrtzidis | 305ec42 | 2009-02-17 20:26:05 +0000 | [diff] [blame] | 860 | /// getParent - Returns the containing DeclContext. |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 861 | DeclContext *getParent() { |
Argyrios Kyrtzidis | 305ec42 | 2009-02-17 20:26:05 +0000 | [diff] [blame] | 862 | return cast<Decl>(this)->getDeclContext(); |
| 863 | } |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 864 | const DeclContext *getParent() const { |
| 865 | return const_cast<DeclContext*>(this)->getParent(); |
Argyrios Kyrtzidis | d2595ec | 2008-10-12 18:40:01 +0000 | [diff] [blame] | 866 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 867 | |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 868 | /// getLexicalParent - Returns the containing lexical DeclContext. May be |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 869 | /// different from getParent, e.g.: |
| 870 | /// |
| 871 | /// namespace A { |
| 872 | /// struct S; |
| 873 | /// } |
| 874 | /// struct A::S {}; // getParent() == namespace 'A' |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 875 | /// // getLexicalParent() == translation unit |
| 876 | /// |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 877 | DeclContext *getLexicalParent() { |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 878 | return cast<Decl>(this)->getLexicalDeclContext(); |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 879 | } |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 880 | const DeclContext *getLexicalParent() const { |
| 881 | return const_cast<DeclContext*>(this)->getLexicalParent(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 882 | } |
Argyrios Kyrtzidis | 048f30a | 2009-06-30 02:35:38 +0000 | [diff] [blame] | 883 | |
Douglas Gregor | e942bbe | 2009-09-10 16:57:35 +0000 | [diff] [blame] | 884 | DeclContext *getLookupParent(); |
| 885 | |
| 886 | const DeclContext *getLookupParent() const { |
| 887 | return const_cast<DeclContext*>(this)->getLookupParent(); |
| 888 | } |
| 889 | |
Argyrios Kyrtzidis | 048f30a | 2009-06-30 02:35:38 +0000 | [diff] [blame] | 890 | ASTContext &getParentASTContext() const { |
| 891 | return cast<Decl>(this)->getASTContext(); |
| 892 | } |
| 893 | |
John McCall | aab9e31 | 2011-02-22 22:25:23 +0000 | [diff] [blame] | 894 | bool isClosure() const { |
| 895 | return DeclKind == Decl::Block; |
| 896 | } |
| 897 | |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 898 | bool isObjCContainer() const { |
Fariborz Jahanian | 80f7753 | 2011-08-22 17:13:51 +0000 | [diff] [blame] | 899 | switch (DeclKind) { |
| 900 | case Decl::ObjCCategory: |
| 901 | case Decl::ObjCCategoryImpl: |
| 902 | case Decl::ObjCImplementation: |
| 903 | case Decl::ObjCInterface: |
| 904 | case Decl::ObjCProtocol: |
| 905 | return true; |
| 906 | } |
| 907 | return false; |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 908 | } |
| 909 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 910 | bool isFunctionOrMethod() const { |
| 911 | switch (DeclKind) { |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 912 | case Decl::Block: |
| 913 | case Decl::ObjCMethod: |
| 914 | return true; |
| 915 | default: |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 916 | return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 917 | } |
| 918 | } |
| 919 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 920 | bool isFileContext() const { |
| 921 | return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; |
| 922 | } |
| 923 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 924 | bool isTranslationUnit() const { |
| 925 | return DeclKind == Decl::TranslationUnit; |
| 926 | } |
| 927 | |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 928 | bool isRecord() const { |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 929 | return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord; |
Argyrios Kyrtzidis | c7ed9c6 | 2008-11-07 22:02:30 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 932 | bool isNamespace() const { |
| 933 | return DeclKind == Decl::Namespace; |
| 934 | } |
| 935 | |
Sebastian Redl | 410c4f2 | 2010-08-31 20:53:31 +0000 | [diff] [blame] | 936 | bool isInlineNamespace() const; |
| 937 | |
Douglas Gregor | bc22163 | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 938 | /// \brief Determines whether this context is dependent on a |
| 939 | /// template parameter. |
| 940 | bool isDependentContext() const; |
| 941 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 942 | /// isTransparentContext - Determines whether this context is a |
| 943 | /// "transparent" context, meaning that the members declared in this |
| 944 | /// context are semantically declared in the nearest enclosing |
| 945 | /// non-transparent (opaque) context but are lexically declared in |
| 946 | /// this context. For example, consider the enumerators of an |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 947 | /// enumeration type: |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 948 | /// @code |
| 949 | /// enum E { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 950 | /// Val1 |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 951 | /// }; |
| 952 | /// @endcode |
| 953 | /// Here, E is a transparent context, so its enumerator (Val1) will |
| 954 | /// appear (semantically) that it is in the same context of E. |
| 955 | /// Examples of transparent contexts include: enumerations (except for |
Sebastian Redl | 410c4f2 | 2010-08-31 20:53:31 +0000 | [diff] [blame] | 956 | /// C++0x scoped enums), and C++ linkage specifications. |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 957 | bool isTransparentContext() const; |
| 958 | |
John McCall | ac65c62 | 2010-10-26 04:59:26 +0000 | [diff] [blame] | 959 | /// \brief Determines whether this context is, or is nested within, |
| 960 | /// a C++ extern "C" linkage spec. |
| 961 | bool isExternCContext() const; |
| 962 | |
Douglas Gregor | 61481da | 2009-09-01 17:22:34 +0000 | [diff] [blame] | 963 | /// \brief Determine whether this declaration context is equivalent |
| 964 | /// to the declaration context DC. |
Sebastian Redl | 7a126a4 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 965 | bool Equals(const DeclContext *DC) const { |
Douglas Gregor | dbdf5e7 | 2010-03-15 15:26:48 +0000 | [diff] [blame] | 966 | return DC && this->getPrimaryContext() == DC->getPrimaryContext(); |
Douglas Gregor | 61481da | 2009-09-01 17:22:34 +0000 | [diff] [blame] | 967 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 968 | |
Douglas Gregor | 6dd38da | 2009-08-27 06:03:53 +0000 | [diff] [blame] | 969 | /// \brief Determine whether this declaration context encloses the |
| 970 | /// declaration context DC. |
Sebastian Redl | 7a126a4 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 971 | bool Encloses(const DeclContext *DC) const; |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 972 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 973 | /// getPrimaryContext - There may be many different |
| 974 | /// declarations of the same entity (including forward declarations |
| 975 | /// of classes, multiple definitions of namespaces, etc.), each with |
| 976 | /// a different set of declarations. This routine returns the |
| 977 | /// "primary" DeclContext structure, which will contain the |
| 978 | /// information needed to perform name lookup into this context. |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 979 | DeclContext *getPrimaryContext(); |
John McCall | 0c01d18 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 980 | const DeclContext *getPrimaryContext() const { |
| 981 | return const_cast<DeclContext*>(this)->getPrimaryContext(); |
| 982 | } |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 983 | |
Sebastian Redl | 7a126a4 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 984 | /// getRedeclContext - Retrieve the context in which an entity conflicts with |
| 985 | /// other entities of the same name, or where it is a redeclaration if the |
Sebastian Redl | 410c4f2 | 2010-08-31 20:53:31 +0000 | [diff] [blame] | 986 | /// two entities are compatible. This skips through transparent contexts. |
Sebastian Redl | 7a126a4 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 987 | DeclContext *getRedeclContext(); |
| 988 | const DeclContext *getRedeclContext() const { |
| 989 | return const_cast<DeclContext *>(this)->getRedeclContext(); |
Douglas Gregor | 17a9b9e | 2009-01-07 02:48:43 +0000 | [diff] [blame] | 990 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 992 | /// \brief Retrieve the nearest enclosing namespace context. |
| 993 | DeclContext *getEnclosingNamespaceContext(); |
| 994 | const DeclContext *getEnclosingNamespaceContext() const { |
| 995 | return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); |
| 996 | } |
| 997 | |
Sebastian Redl | 7a126a4 | 2010-08-31 00:36:30 +0000 | [diff] [blame] | 998 | /// \brief Test if this context is part of the enclosing namespace set of |
| 999 | /// the context NS, as defined in C++0x [namespace.def]p9. If either context |
| 1000 | /// isn't a namespace, this is equivalent to Equals(). |
| 1001 | /// |
| 1002 | /// The enclosing namespace set of a namespace is the namespace and, if it is |
| 1003 | /// inline, its enclosing namespace, recursively. |
| 1004 | bool InEnclosingNamespaceSetOf(const DeclContext *NS) const; |
| 1005 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1006 | /// getNextContext - If this is a DeclContext that may have other |
| 1007 | /// DeclContexts that are semantically connected but syntactically |
| 1008 | /// different, such as C++ namespaces, this routine retrieves the |
| 1009 | /// next DeclContext in the link. Iteration through the chain of |
| 1010 | /// DeclContexts should begin at the primary DeclContext and |
| 1011 | /// continue until this function returns NULL. For example, given: |
| 1012 | /// @code |
| 1013 | /// namespace N { |
| 1014 | /// int x; |
| 1015 | /// } |
| 1016 | /// namespace N { |
| 1017 | /// int y; |
| 1018 | /// } |
| 1019 | /// @endcode |
| 1020 | /// The first occurrence of namespace N will be the primary |
| 1021 | /// DeclContext. Its getNextContext will return the second |
| 1022 | /// occurrence of namespace N. |
| 1023 | DeclContext *getNextContext(); |
| 1024 | |
| 1025 | /// decl_iterator - Iterates through the declarations stored |
| 1026 | /// within this context. |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1027 | class decl_iterator { |
| 1028 | /// Current - The current declaration. |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 1029 | Decl *Current; |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1030 | |
| 1031 | public: |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 1032 | typedef Decl* value_type; |
| 1033 | typedef Decl* reference; |
| 1034 | typedef Decl* pointer; |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1035 | typedef std::forward_iterator_tag iterator_category; |
| 1036 | typedef std::ptrdiff_t difference_type; |
| 1037 | |
| 1038 | decl_iterator() : Current(0) { } |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 1039 | explicit decl_iterator(Decl *C) : Current(C) { } |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1040 | |
| 1041 | reference operator*() const { return Current; } |
| 1042 | pointer operator->() const { return Current; } |
| 1043 | |
Chris Lattner | 96f4468 | 2009-03-28 05:59:45 +0000 | [diff] [blame] | 1044 | decl_iterator& operator++() { |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 1045 | Current = Current->getNextDeclInContext(); |
Chris Lattner | 96f4468 | 2009-03-28 05:59:45 +0000 | [diff] [blame] | 1046 | return *this; |
| 1047 | } |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1048 | |
| 1049 | decl_iterator operator++(int) { |
| 1050 | decl_iterator tmp(*this); |
| 1051 | ++(*this); |
| 1052 | return tmp; |
| 1053 | } |
| 1054 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | friend bool operator==(decl_iterator x, decl_iterator y) { |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1056 | return x.Current == y.Current; |
| 1057 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1058 | friend bool operator!=(decl_iterator x, decl_iterator y) { |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1059 | return x.Current != y.Current; |
| 1060 | } |
| 1061 | }; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1062 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1063 | /// decls_begin/decls_end - Iterate over the declarations stored in |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | /// this context. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1065 | decl_iterator decls_begin() const; |
| 1066 | decl_iterator decls_end() const; |
| 1067 | bool decls_empty() const; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1068 | |
Sebastian Redl | 681d723 | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 1069 | /// noload_decls_begin/end - Iterate over the declarations stored in this |
| 1070 | /// context that are currently loaded; don't attempt to retrieve anything |
| 1071 | /// from an external source. |
| 1072 | decl_iterator noload_decls_begin() const; |
| 1073 | decl_iterator noload_decls_end() const; |
| 1074 | |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1075 | /// specific_decl_iterator - Iterates over a subrange of |
| 1076 | /// declarations stored in a DeclContext, providing only those that |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 1077 | /// are of type SpecificDecl (or a class derived from it). This |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1078 | /// iterator is used, for example, to provide iteration over just |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 1079 | /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1080 | template<typename SpecificDecl> |
| 1081 | class specific_decl_iterator { |
| 1082 | /// Current - The current, underlying declaration iterator, which |
Douglas Gregor | d6f0b4e | 2009-02-02 17:56:05 +0000 | [diff] [blame] | 1083 | /// will either be NULL or will point to a declaration of |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1084 | /// type SpecificDecl. |
| 1085 | DeclContext::decl_iterator Current; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1087 | /// SkipToNextDecl - Advances the current position up to the next |
| 1088 | /// declaration of type SpecificDecl that also meets the criteria |
| 1089 | /// required by Acceptable. |
| 1090 | void SkipToNextDecl() { |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 1091 | while (*Current && !isa<SpecificDecl>(*Current)) |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1092 | ++Current; |
| 1093 | } |
| 1094 | |
| 1095 | public: |
| 1096 | typedef SpecificDecl* value_type; |
| 1097 | typedef SpecificDecl* reference; |
| 1098 | typedef SpecificDecl* pointer; |
| 1099 | typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type |
| 1100 | difference_type; |
| 1101 | typedef std::forward_iterator_tag iterator_category; |
| 1102 | |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 1103 | specific_decl_iterator() : Current() { } |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1104 | |
| 1105 | /// specific_decl_iterator - Construct a new iterator over a |
Douglas Gregor | d6f0b4e | 2009-02-02 17:56:05 +0000 | [diff] [blame] | 1106 | /// subset of the declarations the range [C, |
| 1107 | /// end-of-declarations). If A is non-NULL, it is a pointer to a |
| 1108 | /// member function of SpecificDecl that should return true for |
| 1109 | /// all of the SpecificDecl instances that will be in the subset |
| 1110 | /// of iterators. For example, if you want Objective-C instance |
| 1111 | /// methods, SpecificDecl will be ObjCMethodDecl and A will be |
| 1112 | /// &ObjCMethodDecl::isInstanceMethod. |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 1113 | explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1114 | SkipToNextDecl(); |
| 1115 | } |
| 1116 | |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1117 | reference operator*() const { return cast<SpecificDecl>(*Current); } |
| 1118 | pointer operator->() const { return cast<SpecificDecl>(*Current); } |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1119 | |
| 1120 | specific_decl_iterator& operator++() { |
| 1121 | ++Current; |
| 1122 | SkipToNextDecl(); |
| 1123 | return *this; |
| 1124 | } |
| 1125 | |
| 1126 | specific_decl_iterator operator++(int) { |
| 1127 | specific_decl_iterator tmp(*this); |
| 1128 | ++(*this); |
| 1129 | return tmp; |
| 1130 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1132 | friend bool |
| 1133 | operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) { |
| 1134 | return x.Current == y.Current; |
| 1135 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1136 | |
| 1137 | friend bool |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1138 | operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) { |
| 1139 | return x.Current != y.Current; |
| 1140 | } |
| 1141 | }; |
| 1142 | |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 1143 | /// \brief Iterates over a filtered subrange of declarations stored |
| 1144 | /// in a DeclContext. |
| 1145 | /// |
| 1146 | /// This iterator visits only those declarations that are of type |
| 1147 | /// SpecificDecl (or a class derived from it) and that meet some |
| 1148 | /// additional run-time criteria. This iterator is used, for |
| 1149 | /// example, to provide access to the instance methods within an |
| 1150 | /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and |
| 1151 | /// Acceptable = ObjCMethodDecl::isInstanceMethod). |
| 1152 | template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> |
| 1153 | class filtered_decl_iterator { |
| 1154 | /// Current - The current, underlying declaration iterator, which |
| 1155 | /// will either be NULL or will point to a declaration of |
| 1156 | /// type SpecificDecl. |
| 1157 | DeclContext::decl_iterator Current; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1158 | |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 1159 | /// SkipToNextDecl - Advances the current position up to the next |
| 1160 | /// declaration of type SpecificDecl that also meets the criteria |
| 1161 | /// required by Acceptable. |
| 1162 | void SkipToNextDecl() { |
| 1163 | while (*Current && |
| 1164 | (!isa<SpecificDecl>(*Current) || |
| 1165 | (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) |
| 1166 | ++Current; |
| 1167 | } |
| 1168 | |
| 1169 | public: |
| 1170 | typedef SpecificDecl* value_type; |
| 1171 | typedef SpecificDecl* reference; |
| 1172 | typedef SpecificDecl* pointer; |
| 1173 | typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type |
| 1174 | difference_type; |
| 1175 | typedef std::forward_iterator_tag iterator_category; |
| 1176 | |
| 1177 | filtered_decl_iterator() : Current() { } |
| 1178 | |
| 1179 | /// specific_decl_iterator - Construct a new iterator over a |
| 1180 | /// subset of the declarations the range [C, |
| 1181 | /// end-of-declarations). If A is non-NULL, it is a pointer to a |
| 1182 | /// member function of SpecificDecl that should return true for |
| 1183 | /// all of the SpecificDecl instances that will be in the subset |
| 1184 | /// of iterators. For example, if you want Objective-C instance |
| 1185 | /// methods, SpecificDecl will be ObjCMethodDecl and A will be |
| 1186 | /// &ObjCMethodDecl::isInstanceMethod. |
| 1187 | explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { |
| 1188 | SkipToNextDecl(); |
| 1189 | } |
| 1190 | |
| 1191 | reference operator*() const { return cast<SpecificDecl>(*Current); } |
| 1192 | pointer operator->() const { return cast<SpecificDecl>(*Current); } |
| 1193 | |
| 1194 | filtered_decl_iterator& operator++() { |
| 1195 | ++Current; |
| 1196 | SkipToNextDecl(); |
| 1197 | return *this; |
| 1198 | } |
| 1199 | |
| 1200 | filtered_decl_iterator operator++(int) { |
| 1201 | filtered_decl_iterator tmp(*this); |
| 1202 | ++(*this); |
| 1203 | return tmp; |
| 1204 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1205 | |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 1206 | friend bool |
| 1207 | operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { |
| 1208 | return x.Current == y.Current; |
| 1209 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1210 | |
| 1211 | friend bool |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 1212 | operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { |
| 1213 | return x.Current != y.Current; |
| 1214 | } |
| 1215 | }; |
| 1216 | |
Douglas Gregor | 40f4e69 | 2009-01-20 16:54:50 +0000 | [diff] [blame] | 1217 | /// @brief Add the declaration D into this context. |
| 1218 | /// |
| 1219 | /// This routine should be invoked when the declaration D has first |
| 1220 | /// been declared, to place D into the context where it was |
| 1221 | /// (lexically) defined. Every declaration must be added to one |
| 1222 | /// (and only one!) context, where it can be visited via |
| 1223 | /// [decls_begin(), decls_end()). Once a declaration has been added |
| 1224 | /// to its lexical context, the corresponding DeclContext owns the |
| 1225 | /// declaration. |
| 1226 | /// |
| 1227 | /// If D is also a NamedDecl, it will be made visible within its |
| 1228 | /// semantic context via makeDeclVisibleInContext. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1229 | void addDecl(Decl *D); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1230 | |
John McCall | 3f9a8a6 | 2009-08-11 06:59:38 +0000 | [diff] [blame] | 1231 | /// @brief Add the declaration D to this context without modifying |
| 1232 | /// any lookup tables. |
| 1233 | /// |
| 1234 | /// This is useful for some operations in dependent contexts where |
| 1235 | /// the semantic context might not be dependent; this basically |
| 1236 | /// only happens with friends. |
| 1237 | void addHiddenDecl(Decl *D); |
| 1238 | |
John McCall | 9f54ad4 | 2009-12-10 09:41:52 +0000 | [diff] [blame] | 1239 | /// @brief Removes a declaration from this context. |
| 1240 | void removeDecl(Decl *D); |
| 1241 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1242 | /// lookup_iterator - An iterator that provides access to the results |
| 1243 | /// of looking up a name within this context. |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 1244 | typedef NamedDecl **lookup_iterator; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1245 | |
| 1246 | /// lookup_const_iterator - An iterator that provides non-mutable |
| 1247 | /// access to the results of lookup up a name within this context. |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 1248 | typedef NamedDecl * const * lookup_const_iterator; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1249 | |
John McCall | ea31864 | 2010-08-26 09:15:37 +0000 | [diff] [blame] | 1250 | typedef DeclContextLookupResult lookup_result; |
| 1251 | typedef DeclContextLookupConstResult lookup_const_result; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1252 | |
| 1253 | /// lookup - Find the declarations (if any) with the given Name in |
| 1254 | /// this context. Returns a range of iterators that contains all of |
Douglas Gregor | 40f4e69 | 2009-01-20 16:54:50 +0000 | [diff] [blame] | 1255 | /// the declarations with this name, with object, function, member, |
| 1256 | /// and enumerator names preceding any tag name. Note that this |
| 1257 | /// routine will not look into parent contexts. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1258 | lookup_result lookup(DeclarationName Name); |
| 1259 | lookup_const_result lookup(DeclarationName Name) const; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1260 | |
Douglas Gregor | 40f4e69 | 2009-01-20 16:54:50 +0000 | [diff] [blame] | 1261 | /// @brief Makes a declaration visible within this context. |
| 1262 | /// |
| 1263 | /// This routine makes the declaration D visible to name lookup |
| 1264 | /// within this context and, if this is a transparent context, |
| 1265 | /// within its parent contexts up to the first enclosing |
| 1266 | /// non-transparent context. Making a declaration visible within a |
| 1267 | /// context does not transfer ownership of a declaration, and a |
| 1268 | /// declaration can be visible in many contexts that aren't its |
| 1269 | /// lexical context. |
| 1270 | /// |
| 1271 | /// If D is a redeclaration of an existing declaration that is |
| 1272 | /// visible from this context, as determined by |
| 1273 | /// NamedDecl::declarationReplaces, the previous declaration will be |
| 1274 | /// replaced with D. |
John McCall | ab88d97 | 2009-08-31 22:39:49 +0000 | [diff] [blame] | 1275 | /// |
| 1276 | /// @param Recoverable true if it's okay to not add this decl to |
| 1277 | /// the lookup tables because it can be easily recovered by walking |
| 1278 | /// the declaration chains. |
| 1279 | void makeDeclVisibleInContext(NamedDecl *D, bool Recoverable = true); |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 1280 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1281 | /// udir_iterator - Iterates through the using-directives stored |
| 1282 | /// within this context. |
| 1283 | typedef UsingDirectiveDecl * const * udir_iterator; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1284 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1285 | typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; |
| 1286 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1287 | udir_iterator_range getUsingDirectives() const; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1288 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1289 | udir_iterator using_directives_begin() const { |
| 1290 | return getUsingDirectives().first; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1293 | udir_iterator using_directives_end() const { |
| 1294 | return getUsingDirectives().second; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
John McCall | 0c01d18 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 1297 | // These are all defined in DependentDiagnostic.h. |
| 1298 | class ddiag_iterator; |
| 1299 | inline ddiag_iterator ddiag_begin() const; |
| 1300 | inline ddiag_iterator ddiag_end() const; |
| 1301 | |
Douglas Gregor | c2ee10d | 2009-04-07 17:20:56 +0000 | [diff] [blame] | 1302 | // Low-level accessors |
| 1303 | |
Douglas Gregor | c2ee10d | 2009-04-07 17:20:56 +0000 | [diff] [blame] | 1304 | /// \brief Retrieve the internal representation of the lookup structure. |
John McCall | 0c01d18 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 1305 | StoredDeclsMap* getLookupPtr() const { return LookupPtr; } |
Douglas Gregor | c2ee10d | 2009-04-07 17:20:56 +0000 | [diff] [blame] | 1306 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1307 | /// \brief Whether this DeclContext has external storage containing |
| 1308 | /// additional declarations that are lexically in this context. |
| 1309 | bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; } |
| 1310 | |
| 1311 | /// \brief State whether this DeclContext has external storage for |
| 1312 | /// declarations lexically in this context. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | void setHasExternalLexicalStorage(bool ES = true) { |
| 1314 | ExternalLexicalStorage = ES; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | /// \brief Whether this DeclContext has external storage containing |
| 1318 | /// additional declarations that are visible in this context. |
| 1319 | bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; } |
| 1320 | |
| 1321 | /// \brief State whether this DeclContext has external storage for |
| 1322 | /// declarations visible in this context. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | void setHasExternalVisibleStorage(bool ES = true) { |
| 1324 | ExternalVisibleStorage = ES; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 1327 | /// \brief Determine whether the given declaration is stored in the list of |
| 1328 | /// declarations lexically within this context. |
| 1329 | bool isDeclInLexicalTraversal(const Decl *D) const { |
| 1330 | return D && (D->NextDeclInContext || D == FirstDecl || D == LastDecl); |
| 1331 | } |
| 1332 | |
Argyrios Kyrtzidis | 3d7641e | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 1333 | static bool classof(const Decl *D); |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 1334 | static bool classof(const DeclContext *D) { return true; } |
Sean Hunt | 9a55591 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 1335 | #define DECL(NAME, BASE) |
| 1336 | #define DECL_CONTEXT(NAME) \ |
| 1337 | static bool classof(const NAME##Decl *D) { return true; } |
| 1338 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 1339 | |
Anders Carlsson | 8483443 | 2009-12-14 00:51:04 +0000 | [diff] [blame] | 1340 | void dumpDeclContext() const; |
Anders Carlsson | 2b7d8dd | 2009-12-09 17:27:46 +0000 | [diff] [blame] | 1341 | |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 1342 | private: |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1343 | void LoadLexicalDeclsFromExternalStorage() const; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1344 | |
John McCall | 0c01d18 | 2010-03-24 05:22:00 +0000 | [diff] [blame] | 1345 | friend class DependentDiagnostic; |
| 1346 | StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const; |
| 1347 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1348 | void buildLookup(DeclContext *DCtx); |
| 1349 | void makeDeclVisibleInContextImpl(NamedDecl *D); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1350 | }; |
| 1351 | |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 1352 | inline bool Decl::isTemplateParameter() const { |
Douglas Gregor | 79c2278 | 2010-01-16 20:21:20 +0000 | [diff] [blame] | 1353 | return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm || |
| 1354 | getKind() == TemplateTemplateParm; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
John McCall | 80cd64a | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 1357 | // Specialization selected when ToTy is not a known subclass of DeclContext. |
| 1358 | template <class ToTy, |
| 1359 | bool IsKnownSubtype = ::llvm::is_base_of< DeclContext, ToTy>::value> |
| 1360 | struct cast_convert_decl_context { |
| 1361 | static const ToTy *doit(const DeclContext *Val) { |
| 1362 | return static_cast<const ToTy*>(Decl::castFromDeclContext(Val)); |
| 1363 | } |
| 1364 | |
| 1365 | static ToTy *doit(DeclContext *Val) { |
| 1366 | return static_cast<ToTy*>(Decl::castFromDeclContext(Val)); |
| 1367 | } |
| 1368 | }; |
| 1369 | |
| 1370 | // Specialization selected when ToTy is a known subclass of DeclContext. |
| 1371 | template <class ToTy> |
| 1372 | struct cast_convert_decl_context<ToTy, true> { |
| 1373 | static const ToTy *doit(const DeclContext *Val) { |
| 1374 | return static_cast<const ToTy*>(Val); |
| 1375 | } |
| 1376 | |
| 1377 | static ToTy *doit(DeclContext *Val) { |
| 1378 | return static_cast<ToTy*>(Val); |
| 1379 | } |
| 1380 | }; |
| 1381 | |
| 1382 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1383 | } // end clang. |
| 1384 | |
| 1385 | namespace llvm { |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 1386 | |
John McCall | 80cd64a | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 1387 | /// isa<T>(DeclContext*) |
Eli Friedman | 4d50934 | 2011-05-21 19:15:39 +0000 | [diff] [blame] | 1388 | template <typename To> |
| 1389 | struct isa_impl<To, ::clang::DeclContext> { |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 1390 | static bool doit(const ::clang::DeclContext &Val) { |
Eli Friedman | 4d50934 | 2011-05-21 19:15:39 +0000 | [diff] [blame] | 1391 | return To::classofKind(Val.getDeclKind()); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1392 | } |
| 1393 | }; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1394 | |
John McCall | 80cd64a | 2010-01-29 01:45:37 +0000 | [diff] [blame] | 1395 | /// cast<T>(DeclContext*) |
| 1396 | template<class ToTy> |
| 1397 | struct cast_convert_val<ToTy, |
| 1398 | const ::clang::DeclContext,const ::clang::DeclContext> { |
| 1399 | static const ToTy &doit(const ::clang::DeclContext &Val) { |
| 1400 | return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); |
| 1401 | } |
| 1402 | }; |
| 1403 | template<class ToTy> |
| 1404 | struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> { |
| 1405 | static ToTy &doit(::clang::DeclContext &Val) { |
| 1406 | return *::clang::cast_convert_decl_context<ToTy>::doit(&Val); |
| 1407 | } |
| 1408 | }; |
| 1409 | template<class ToTy> |
| 1410 | struct cast_convert_val<ToTy, |
| 1411 | const ::clang::DeclContext*, const ::clang::DeclContext*> { |
| 1412 | static const ToTy *doit(const ::clang::DeclContext *Val) { |
| 1413 | return ::clang::cast_convert_decl_context<ToTy>::doit(Val); |
| 1414 | } |
| 1415 | }; |
| 1416 | template<class ToTy> |
| 1417 | struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> { |
| 1418 | static ToTy *doit(::clang::DeclContext *Val) { |
| 1419 | return ::clang::cast_convert_decl_context<ToTy>::doit(Val); |
| 1420 | } |
| 1421 | }; |
| 1422 | |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 1423 | /// Implement cast_convert_val for Decl -> DeclContext conversions. |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1424 | template<class FromTy> |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 1425 | struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 1426 | static ::clang::DeclContext &doit(const FromTy &Val) { |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 1427 | return *FromTy::castToDeclContext(&Val); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1428 | } |
| 1429 | }; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1430 | |
| 1431 | template<class FromTy> |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 1432 | struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 1433 | static ::clang::DeclContext *doit(const FromTy *Val) { |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 1434 | return FromTy::castToDeclContext(Val); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1435 | } |
| 1436 | }; |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 1437 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1438 | template<class FromTy> |
| 1439 | struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { |
| 1440 | static const ::clang::DeclContext &doit(const FromTy &Val) { |
| 1441 | return *FromTy::castToDeclContext(&Val); |
| 1442 | } |
| 1443 | }; |
| 1444 | |
| 1445 | template<class FromTy> |
| 1446 | struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { |
| 1447 | static const ::clang::DeclContext *doit(const FromTy *Val) { |
| 1448 | return FromTy::castToDeclContext(Val); |
| 1449 | } |
| 1450 | }; |
| 1451 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1452 | } // end namespace llvm |
| 1453 | |
| 1454 | #endif |