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