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" |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 19 | // FIXME: Layering violation |
| 20 | #include "clang/Parse/AccessSpecifier.h" |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 21 | #include "llvm/Support/PrettyStackTrace.h" |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/PointerUnion.h" |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 23 | |
| 24 | namespace clang { |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 25 | class DeclContext; |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 26 | class TranslationUnitDecl; |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 27 | class NamespaceDecl; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 28 | class UsingDirectiveDecl; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 29 | class NamedDecl; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 30 | class FunctionDecl; |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 31 | class CXXRecordDecl; |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 32 | class EnumDecl; |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 33 | class ObjCMethodDecl; |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 34 | class ObjCContainerDecl; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 35 | class ObjCInterfaceDecl; |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 36 | class ObjCCategoryDecl; |
| 37 | class ObjCProtocolDecl; |
| 38 | class ObjCImplementationDecl; |
| 39 | class ObjCCategoryImplDecl; |
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; |
Chris Lattner | 0eda3b3 | 2009-03-29 04:32:54 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | namespace llvm { |
| 47 | // DeclContext* is only 4-byte aligned on 32-bit systems. |
| 48 | template<> |
| 49 | class PointerLikeTypeTraits<clang::DeclContext*> { |
| 50 | typedef clang::DeclContext* PT; |
| 51 | public: |
| 52 | static inline void *getAsVoidPointer(PT P) { return P; } |
| 53 | static inline PT getFromVoidPointer(void *P) { |
| 54 | return static_cast<PT>(P); |
| 55 | } |
| 56 | enum { NumLowBitsAvailable = 2 }; |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | namespace clang { |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 61 | |
| 62 | /// Decl - This represents one declaration (or definition), e.g. a variable, |
| 63 | /// typedef, function, struct, etc. |
| 64 | /// |
| 65 | class Decl { |
| 66 | public: |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 67 | /// \brief Lists the kind of concrete classes of Decl. |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 68 | enum Kind { |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 69 | #define DECL(Derived, Base) Derived, |
| 70 | #define DECL_RANGE(CommonBase, Start, End) \ |
| 71 | CommonBase##First = Start, CommonBase##Last = End, |
| 72 | #define LAST_DECL_RANGE(CommonBase, Start, End) \ |
| 73 | CommonBase##First = Start, CommonBase##Last = End |
| 74 | #include "clang/AST/DeclNodes.def" |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 77 | /// IdentifierNamespace - According to C99 6.2.3, there are four |
| 78 | /// namespaces, labels, tags, members and ordinary |
| 79 | /// identifiers. These are meant as bitmasks, so that searches in |
| 80 | /// C++ can look into the "tag" namespace during ordinary lookup. We |
| 81 | /// use additional namespaces for Objective-C entities. |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 82 | enum IdentifierNamespace { |
Douglas Gregor | 2ce52f3 | 2008-04-13 21:07:44 +0000 | [diff] [blame] | 83 | IDNS_Label = 0x1, |
| 84 | IDNS_Tag = 0x2, |
| 85 | IDNS_Member = 0x4, |
Douglas Gregor | 7dda67d | 2009-02-05 19:25:20 +0000 | [diff] [blame] | 86 | IDNS_Ordinary = 0x8, |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 87 | IDNS_ObjCProtocol = 0x10, |
| 88 | IDNS_ObjCImplementation = 0x20, |
| 89 | IDNS_ObjCCategoryImpl = 0x40 |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /// ObjCDeclQualifier - Qualifier used on types in method declarations |
| 93 | /// for remote messaging. They are meant for the arguments though and |
| 94 | /// applied to the Decls (ObjCMethodDecl and ParmVarDecl). |
| 95 | enum ObjCDeclQualifier { |
| 96 | OBJC_TQ_None = 0x0, |
| 97 | OBJC_TQ_In = 0x1, |
| 98 | OBJC_TQ_Inout = 0x2, |
| 99 | OBJC_TQ_Out = 0x4, |
| 100 | OBJC_TQ_Bycopy = 0x8, |
| 101 | OBJC_TQ_Byref = 0x10, |
| 102 | OBJC_TQ_Oneway = 0x20 |
| 103 | }; |
| 104 | |
| 105 | private: |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 106 | /// NextDeclInContext - The next declaration within the same lexical |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 107 | /// DeclContext. These pointers form the linked list that is |
| 108 | /// traversed via DeclContext's decls_begin()/decls_end(). |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 109 | Decl *NextDeclInContext; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 110 | |
| 111 | friend class DeclContext; |
| 112 | |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 113 | struct MultipleDC { |
| 114 | DeclContext *SemanticDC; |
| 115 | DeclContext *LexicalDC; |
| 116 | }; |
| 117 | |
| 118 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 119 | /// DeclCtx - Holds either a DeclContext* or a MultipleDC*. |
| 120 | /// For declarations that don't contain C++ scope specifiers, it contains |
| 121 | /// the DeclContext where the Decl was declared. |
| 122 | /// For declarations with C++ scope specifiers, it contains a MultipleDC* |
| 123 | /// with the context where it semantically belongs (SemanticDC) and the |
| 124 | /// context where it was lexically declared (LexicalDC). |
| 125 | /// e.g.: |
| 126 | /// |
| 127 | /// namespace A { |
| 128 | /// void f(); // SemanticDC == LexicalDC == 'namespace A' |
| 129 | /// } |
| 130 | /// void A::f(); // SemanticDC == namespace 'A' |
| 131 | /// // LexicalDC == global namespace |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 132 | llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 133 | |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 134 | inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); } |
| 135 | inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); } |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 136 | inline MultipleDC *getMultipleDC() const { |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 137 | return DeclCtx.get<MultipleDC*>(); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 138 | } |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 139 | inline DeclContext *getSemanticDC() const { |
Chris Lattner | ee219fd | 2009-03-29 06:06:59 +0000 | [diff] [blame] | 140 | return DeclCtx.get<DeclContext*>(); |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Daniel Dunbar | 39d7650 | 2009-03-04 02:26:41 +0000 | [diff] [blame] | 143 | /// Loc - The location that this decl. |
| 144 | SourceLocation Loc; |
| 145 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 146 | /// DeclKind - This indicates which class this is. |
| 147 | Kind DeclKind : 8; |
| 148 | |
| 149 | /// InvalidDecl - This indicates a semantic error occurred. |
| 150 | unsigned int InvalidDecl : 1; |
| 151 | |
| 152 | /// HasAttrs - This indicates whether the decl has attributes or not. |
| 153 | unsigned int HasAttrs : 1; |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 154 | |
Douglas Gregor | 6b3945f | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 155 | /// Implicit - Whether this declaration was implicitly generated by |
| 156 | /// the implementation rather than explicitly written by the user. |
| 157 | bool Implicit : 1; |
| 158 | |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame^] | 159 | /// \brief Whether this declaration was "used", meaning that a definition is |
| 160 | /// required. |
| 161 | bool Used : 1; |
| 162 | |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 163 | /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 164 | unsigned IdentifierNamespace : 8; |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 165 | |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 166 | #ifndef NDEBUG |
| 167 | void CheckAccessDeclContext() const; |
| 168 | #else |
| 169 | void CheckAccessDeclContext() const { } |
| 170 | #endif |
| 171 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 172 | protected: |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 173 | /// Access - Used by C++ decls for the access specifier. |
| 174 | // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum |
| 175 | unsigned Access : 2; |
| 176 | friend class CXXClassMemberWrapper; |
| 177 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 178 | Decl(Kind DK, DeclContext *DC, SourceLocation L) |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 179 | : NextDeclInContext(0), DeclCtx(DC), |
Daniel Dunbar | 39d7650 | 2009-03-04 02:26:41 +0000 | [diff] [blame] | 180 | Loc(L), DeclKind(DK), InvalidDecl(0), |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame^] | 181 | HasAttrs(false), Implicit(false), Used(false), |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 182 | IdentifierNamespace(getIdentifierNamespaceForKind(DK)), Access(AS_none) { |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 183 | if (Decl::CollectingStats()) addDeclKind(DK); |
| 184 | } |
Sam Bishop | 1bb1963 | 2008-04-11 18:04:39 +0000 | [diff] [blame] | 185 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 186 | virtual ~Decl(); |
Sam Bishop | 1bb1963 | 2008-04-11 18:04:39 +0000 | [diff] [blame] | 187 | |
| 188 | public: |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 189 | SourceLocation getLocation() const { return Loc; } |
| 190 | void setLocation(SourceLocation L) { Loc = L; } |
| 191 | |
| 192 | Kind getKind() const { return DeclKind; } |
| 193 | const char *getDeclKindName() const; |
| 194 | |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 195 | Decl *getNextDeclInContext() { return NextDeclInContext; } |
| 196 | const Decl *getNextDeclInContext() const { return NextDeclInContext; } |
Chris Lattner | 96f4468 | 2009-03-28 05:59:45 +0000 | [diff] [blame] | 197 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 198 | DeclContext *getDeclContext() { |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 199 | if (isInSemaDC()) |
| 200 | return getSemanticDC(); |
| 201 | return getMultipleDC()->SemanticDC; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 202 | } |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 203 | const DeclContext *getDeclContext() const { |
| 204 | return const_cast<Decl*>(this)->getDeclContext(); |
| 205 | } |
| 206 | |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 207 | void setAccess(AccessSpecifier AS) { |
Anders Carlsson | b8547e8 | 2009-03-25 20:19:57 +0000 | [diff] [blame] | 208 | Access = AS; |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 209 | CheckAccessDeclContext(); |
Anders Carlsson | b8547e8 | 2009-03-25 20:19:57 +0000 | [diff] [blame] | 210 | } |
Anders Carlsson | 1329c27 | 2009-03-25 23:38:06 +0000 | [diff] [blame] | 211 | |
| 212 | AccessSpecifier getAccess() const { |
| 213 | CheckAccessDeclContext(); |
| 214 | return AccessSpecifier(Access); |
| 215 | } |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 216 | |
Chris Lattner | 76a642f | 2009-02-15 22:43:40 +0000 | [diff] [blame] | 217 | bool hasAttrs() const { return HasAttrs; } |
Douglas Gregor | 68584ed | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 218 | void addAttr(ASTContext &Context, Attr *attr); |
| 219 | const Attr *getAttrs(ASTContext &Context) const { |
Chris Lattner | 81abbdd | 2009-03-21 06:27:31 +0000 | [diff] [blame] | 220 | if (!HasAttrs) return 0; // common case, no attributes. |
Douglas Gregor | 68584ed | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 221 | return getAttrsImpl(Context); // Uncommon case, out of line hash lookup. |
Chris Lattner | 81abbdd | 2009-03-21 06:27:31 +0000 | [diff] [blame] | 222 | } |
Douglas Gregor | 68584ed | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 223 | void swapAttrs(ASTContext &Context, Decl *D); |
| 224 | void invalidateAttrs(ASTContext &Context); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 225 | |
Douglas Gregor | 68584ed | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 226 | template<typename T> const T *getAttr(ASTContext &Context) const { |
| 227 | for (const Attr *attr = getAttrs(Context); attr; attr = attr->getNext()) |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 228 | if (const T *V = dyn_cast<T>(attr)) |
| 229 | return V; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | |
Douglas Gregor | 68584ed | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 233 | template<typename T> bool hasAttr(ASTContext &Context) const { |
| 234 | return getAttr<T>(Context) != 0; |
Chris Lattner | 115cafc | 2009-04-12 20:07:59 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 237 | /// setInvalidDecl - Indicates the Decl had a semantic error. This |
| 238 | /// allows for graceful error recovery. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 239 | void setInvalidDecl(bool Invalid = true) { InvalidDecl = Invalid; } |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 240 | bool isInvalidDecl() const { return (bool) InvalidDecl; } |
Douglas Gregor | 6b3945f | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 241 | |
| 242 | /// isImplicit - Indicates whether the declaration was implicitly |
| 243 | /// generated by the implementation. If false, this declaration |
| 244 | /// was written explicitly in the source code. |
| 245 | bool isImplicit() const { return Implicit; } |
| 246 | void setImplicit(bool I = true) { Implicit = I; } |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 247 | |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame^] | 248 | /// \brief Whether this declaration was used, meaning that a definition |
| 249 | /// is required. |
| 250 | bool isUsed() const { return Used; } |
| 251 | void setUsed(bool U = true) { Used = U; } |
| 252 | |
Douglas Gregor | cc63668 | 2009-02-17 23:15:12 +0000 | [diff] [blame] | 253 | unsigned getIdentifierNamespace() const { |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 254 | return IdentifierNamespace; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 255 | } |
Chris Lattner | d62fdc4 | 2009-01-06 07:16:40 +0000 | [diff] [blame] | 256 | bool isInIdentifierNamespace(unsigned NS) const { |
| 257 | return getIdentifierNamespace() & NS; |
| 258 | } |
Chris Lattner | 769dbdf | 2009-03-27 20:18:19 +0000 | [diff] [blame] | 259 | static unsigned getIdentifierNamespaceForKind(Kind DK); |
| 260 | |
Chris Lattner | d62fdc4 | 2009-01-06 07:16:40 +0000 | [diff] [blame] | 261 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 262 | /// getLexicalDeclContext - The declaration context where this Decl was |
| 263 | /// lexically declared (LexicalDC). May be different from |
| 264 | /// getDeclContext() (SemanticDC). |
| 265 | /// e.g.: |
| 266 | /// |
| 267 | /// namespace A { |
| 268 | /// void f(); // SemanticDC == LexicalDC == 'namespace A' |
| 269 | /// } |
| 270 | /// void A::f(); // SemanticDC == namespace 'A' |
| 271 | /// // LexicalDC == global namespace |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 272 | DeclContext *getLexicalDeclContext() { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 273 | if (isInSemaDC()) |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 274 | return getSemanticDC(); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 275 | return getMultipleDC()->LexicalDC; |
| 276 | } |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 277 | const DeclContext *getLexicalDeclContext() const { |
| 278 | return const_cast<Decl*>(this)->getLexicalDeclContext(); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 279 | } |
Argyrios Kyrtzidis | f5cecfb | 2009-06-17 22:49:50 +0000 | [diff] [blame] | 280 | |
| 281 | bool isOutOfLine() const { |
| 282 | return getLexicalDeclContext() != getDeclContext(); |
| 283 | } |
Chris Lattner | 10d8379 | 2009-03-27 18:46:15 +0000 | [diff] [blame] | 284 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 285 | /// setDeclContext - Set both the semantic and lexical DeclContext |
| 286 | /// to DC. |
| 287 | void setDeclContext(DeclContext *DC); |
| 288 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 289 | void setLexicalDeclContext(DeclContext *DC); |
| 290 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 291 | // isDefinedOutsideFunctionOrMethod - This predicate returns true if this |
| 292 | // scoped decl is defined outside the current function or method. This is |
| 293 | // roughly global variables and functions, but also handles enums (which could |
| 294 | // be defined inside or outside a function etc). |
| 295 | bool isDefinedOutsideFunctionOrMethod() const; |
| 296 | |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 297 | /// getBody - If this Decl represents a declaration for a body of code, |
| 298 | /// such as a function or method definition, this method returns the |
| 299 | /// top-level Stmt* of that body. Otherwise this method returns null. |
| 300 | virtual Stmt* getBody(ASTContext &Context) const { return 0; } |
| 301 | |
| 302 | /// getCompoundBody - Returns getBody(), dyn_casted to a CompoundStmt. |
| 303 | CompoundStmt* getCompoundBody(ASTContext &Context) const; |
| 304 | |
| 305 | /// getBodyRBrace - Gets the right brace of the body, if a body exists. |
| 306 | /// This works whether the body is a CompoundStmt or a CXXTryStmt. |
| 307 | SourceLocation getBodyRBrace(ASTContext &Context) const; |
| 308 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 309 | // global temp stats (until we have a per-module visitor) |
| 310 | static void addDeclKind(Kind k); |
| 311 | static bool CollectingStats(bool Enable = false); |
| 312 | static void PrintStats(); |
| 313 | |
Anders Carlsson | 67e3320 | 2009-06-13 00:08:58 +0000 | [diff] [blame] | 314 | /// isTemplateParameter - Determines whether this declaration is a |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 315 | /// template parameter. |
| 316 | bool isTemplateParameter() const; |
Anders Carlsson | 67e3320 | 2009-06-13 00:08:58 +0000 | [diff] [blame] | 317 | |
| 318 | /// isTemplateParameter - Determines whether this declaration is a |
| 319 | /// template parameter pack. |
| 320 | bool isTemplateParameterPack() const; |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 321 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 322 | // Implement isa/cast/dyncast/etc. |
| 323 | static bool classof(const Decl *) { return true; } |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 324 | static DeclContext *castToDeclContext(const Decl *); |
| 325 | static Decl *castFromDeclContext(const DeclContext *); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 326 | |
Sam Bishop | bb45c51 | 2008-04-11 15:01:25 +0000 | [diff] [blame] | 327 | /// Destroy - Call destructors and release memory. |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 328 | virtual void Destroy(ASTContext& C); |
Sam Bishop | bb45c51 | 2008-04-11 15:01:25 +0000 | [diff] [blame] | 329 | |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 330 | void print(llvm::raw_ostream &Out, ASTContext &Context, |
| 331 | unsigned Indentation = 0); |
| 332 | void print(llvm::raw_ostream &Out, ASTContext &Context, |
| 333 | const PrintingPolicy &Policy, unsigned Indentation = 0); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 334 | static void printGroup(Decl** Begin, unsigned NumDecls, |
| 335 | llvm::raw_ostream &Out, ASTContext &Context, |
| 336 | const PrintingPolicy &Policy, |
| 337 | unsigned Indentation = 0); |
Douglas Gregor | 4fe0c8e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 338 | void dump(ASTContext &Context); |
| 339 | |
Chris Lattner | 81abbdd | 2009-03-21 06:27:31 +0000 | [diff] [blame] | 340 | private: |
Douglas Gregor | 68584ed | 2009-06-18 16:11:24 +0000 | [diff] [blame] | 341 | const Attr *getAttrsImpl(ASTContext &Context) const; |
Chris Lattner | 81abbdd | 2009-03-21 06:27:31 +0000 | [diff] [blame] | 342 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 343 | }; |
| 344 | |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 345 | /// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when |
| 346 | /// doing something to a specific decl. |
| 347 | class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry { |
| 348 | Decl *TheDecl; |
| 349 | SourceLocation Loc; |
| 350 | SourceManager &SM; |
| 351 | const char *Message; |
| 352 | public: |
| 353 | PrettyStackTraceDecl(Decl *theDecl, SourceLocation L, |
| 354 | SourceManager &sm, const char *Msg) |
| 355 | : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {} |
| 356 | |
| 357 | virtual void print(llvm::raw_ostream &OS) const; |
| 358 | }; |
| 359 | |
| 360 | |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 361 | /// 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] | 362 | /// can act as declaration contexts. These decls are (only the top classes |
| 363 | /// that directly derive from DeclContext are mentioned, not their subclasses): |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 364 | /// |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 365 | /// TranslationUnitDecl |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 366 | /// NamespaceDecl |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 367 | /// FunctionDecl |
Argyrios Kyrtzidis | 1ad4dd7 | 2009-02-16 14:28:33 +0000 | [diff] [blame] | 368 | /// TagDecl |
Argyrios Kyrtzidis | d3bb44f | 2008-06-09 21:05:31 +0000 | [diff] [blame] | 369 | /// ObjCMethodDecl |
Argyrios Kyrtzidis | 1ad4dd7 | 2009-02-16 14:28:33 +0000 | [diff] [blame] | 370 | /// ObjCContainerDecl |
| 371 | /// ObjCCategoryImplDecl |
| 372 | /// ObjCImplementationDecl |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 373 | /// LinkageSpecDecl |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 374 | /// BlockDecl |
Argyrios Kyrtzidis | 1ad4dd7 | 2009-02-16 14:28:33 +0000 | [diff] [blame] | 375 | /// |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 376 | class DeclContext { |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 377 | /// DeclKind - This indicates which class this is. |
| 378 | Decl::Kind DeclKind : 8; |
| 379 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 380 | /// \brief Whether this declaration context also has some external |
| 381 | /// storage that contains additional declarations that are lexically |
| 382 | /// part of this context. |
| 383 | mutable bool ExternalLexicalStorage : 1; |
| 384 | |
| 385 | /// \brief Whether this declaration context also has some external |
| 386 | /// storage that contains additional declarations that are visible |
| 387 | /// in this context. |
| 388 | mutable bool ExternalVisibleStorage : 1; |
| 389 | |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 390 | /// \brief Pointer to the data structure used to lookup declarations |
| 391 | /// within this context, which is a DenseMap<DeclarationName, |
| 392 | /// StoredDeclsList>. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 393 | mutable void* LookupPtr; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 394 | |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 395 | /// FirstDecl - The first declaration stored within this declaration |
| 396 | /// context. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 397 | mutable Decl *FirstDecl; |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 398 | |
| 399 | /// LastDecl - The last declaration stored within this declaration |
| 400 | /// context. FIXME: We could probably cache this value somewhere |
| 401 | /// outside of the DeclContext, to reduce the size of DeclContext by |
| 402 | /// another pointer. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 403 | mutable Decl *LastDecl; |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 404 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 405 | protected: |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 406 | DeclContext(Decl::Kind K) |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 407 | : DeclKind(K), ExternalLexicalStorage(false), |
| 408 | ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0), |
| 409 | LastDecl(0) { } |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 410 | |
| 411 | void DestroyDecls(ASTContext &C); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 412 | |
| 413 | public: |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 414 | ~DeclContext(); |
| 415 | |
Argyrios Kyrtzidis | 9b9ca01 | 2009-01-13 13:11:58 +0000 | [diff] [blame] | 416 | Decl::Kind getDeclKind() const { |
| 417 | return DeclKind; |
| 418 | } |
Steve Naroff | 0a47393 | 2009-01-20 19:53:53 +0000 | [diff] [blame] | 419 | const char *getDeclKindName() const; |
Argyrios Kyrtzidis | 9b9ca01 | 2009-01-13 13:11:58 +0000 | [diff] [blame] | 420 | |
Argyrios Kyrtzidis | 305ec42 | 2009-02-17 20:26:05 +0000 | [diff] [blame] | 421 | /// getParent - Returns the containing DeclContext. |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 422 | DeclContext *getParent() { |
Argyrios Kyrtzidis | 305ec42 | 2009-02-17 20:26:05 +0000 | [diff] [blame] | 423 | return cast<Decl>(this)->getDeclContext(); |
| 424 | } |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 425 | const DeclContext *getParent() const { |
| 426 | return const_cast<DeclContext*>(this)->getParent(); |
Argyrios Kyrtzidis | d2595ec | 2008-10-12 18:40:01 +0000 | [diff] [blame] | 427 | } |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 428 | |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 429 | /// getLexicalParent - Returns the containing lexical DeclContext. May be |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 430 | /// different from getParent, e.g.: |
| 431 | /// |
| 432 | /// namespace A { |
| 433 | /// struct S; |
| 434 | /// } |
| 435 | /// struct A::S {}; // getParent() == namespace 'A' |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 436 | /// // getLexicalParent() == translation unit |
| 437 | /// |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 438 | DeclContext *getLexicalParent() { |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 439 | return cast<Decl>(this)->getLexicalDeclContext(); |
Argyrios Kyrtzidis | 77407b8 | 2008-11-19 18:01:13 +0000 | [diff] [blame] | 440 | } |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 441 | const DeclContext *getLexicalParent() const { |
| 442 | return const_cast<DeclContext*>(this)->getLexicalParent(); |
| 443 | } |
| 444 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 445 | bool isFunctionOrMethod() const { |
| 446 | switch (DeclKind) { |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 447 | case Decl::Block: |
| 448 | case Decl::ObjCMethod: |
| 449 | return true; |
| 450 | default: |
| 451 | return DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 455 | bool isFileContext() const { |
| 456 | return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; |
| 457 | } |
| 458 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 459 | bool isTranslationUnit() const { |
| 460 | return DeclKind == Decl::TranslationUnit; |
| 461 | } |
| 462 | |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 463 | bool isRecord() const { |
Douglas Gregor | 6510079 | 2009-02-26 00:02:51 +0000 | [diff] [blame] | 464 | return DeclKind >= Decl::RecordFirst && DeclKind <= Decl::RecordLast; |
Argyrios Kyrtzidis | c7ed9c6 | 2008-11-07 22:02:30 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 467 | bool isNamespace() const { |
| 468 | return DeclKind == Decl::Namespace; |
| 469 | } |
| 470 | |
Douglas Gregor | bc22163 | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 471 | /// \brief Determines whether this context is dependent on a |
| 472 | /// template parameter. |
| 473 | bool isDependentContext() const; |
| 474 | |
Douglas Gregor | 074149e | 2009-01-05 19:45:36 +0000 | [diff] [blame] | 475 | /// isTransparentContext - Determines whether this context is a |
| 476 | /// "transparent" context, meaning that the members declared in this |
| 477 | /// context are semantically declared in the nearest enclosing |
| 478 | /// non-transparent (opaque) context but are lexically declared in |
| 479 | /// this context. For example, consider the enumerators of an |
| 480 | /// enumeration type: |
| 481 | /// @code |
| 482 | /// enum E { |
| 483 | /// Val1 |
| 484 | /// }; |
| 485 | /// @endcode |
| 486 | /// Here, E is a transparent context, so its enumerator (Val1) will |
| 487 | /// appear (semantically) that it is in the same context of E. |
| 488 | /// Examples of transparent contexts include: enumerations (except for |
| 489 | /// C++0x scoped enums), C++ linkage specifications, and C++0x |
| 490 | /// inline namespaces. |
| 491 | bool isTransparentContext() const; |
| 492 | |
Argyrios Kyrtzidis | ef6e647 | 2008-11-08 17:17:31 +0000 | [diff] [blame] | 493 | bool Encloses(DeclContext *DC) const { |
| 494 | for (; DC; DC = DC->getParent()) |
| 495 | if (DC == this) |
| 496 | return true; |
| 497 | return false; |
| 498 | } |
| 499 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 500 | /// getPrimaryContext - There may be many different |
| 501 | /// declarations of the same entity (including forward declarations |
| 502 | /// of classes, multiple definitions of namespaces, etc.), each with |
| 503 | /// a different set of declarations. This routine returns the |
| 504 | /// "primary" DeclContext structure, which will contain the |
| 505 | /// information needed to perform name lookup into this context. |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 506 | DeclContext *getPrimaryContext(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 507 | |
Douglas Gregor | ce35607 | 2009-01-06 23:51:29 +0000 | [diff] [blame] | 508 | /// getLookupContext - Retrieve the innermost non-transparent |
| 509 | /// context of this context, which corresponds to the innermost |
| 510 | /// location from which name lookup can find the entities in this |
| 511 | /// context. |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 512 | DeclContext *getLookupContext(); |
| 513 | const DeclContext *getLookupContext() const { |
| 514 | return const_cast<DeclContext *>(this)->getLookupContext(); |
Douglas Gregor | 17a9b9e | 2009-01-07 02:48:43 +0000 | [diff] [blame] | 515 | } |
Chris Lattner | 0cf2b19 | 2009-03-27 19:19:59 +0000 | [diff] [blame] | 516 | |
Douglas Gregor | 88b7094 | 2009-02-25 22:02:03 +0000 | [diff] [blame] | 517 | /// \brief Retrieve the nearest enclosing namespace context. |
| 518 | DeclContext *getEnclosingNamespaceContext(); |
| 519 | const DeclContext *getEnclosingNamespaceContext() const { |
| 520 | return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext(); |
| 521 | } |
| 522 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 523 | /// getNextContext - If this is a DeclContext that may have other |
| 524 | /// DeclContexts that are semantically connected but syntactically |
| 525 | /// different, such as C++ namespaces, this routine retrieves the |
| 526 | /// next DeclContext in the link. Iteration through the chain of |
| 527 | /// DeclContexts should begin at the primary DeclContext and |
| 528 | /// continue until this function returns NULL. For example, given: |
| 529 | /// @code |
| 530 | /// namespace N { |
| 531 | /// int x; |
| 532 | /// } |
| 533 | /// namespace N { |
| 534 | /// int y; |
| 535 | /// } |
| 536 | /// @endcode |
| 537 | /// The first occurrence of namespace N will be the primary |
| 538 | /// DeclContext. Its getNextContext will return the second |
| 539 | /// occurrence of namespace N. |
| 540 | DeclContext *getNextContext(); |
| 541 | |
| 542 | /// decl_iterator - Iterates through the declarations stored |
| 543 | /// within this context. |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 544 | class decl_iterator { |
| 545 | /// Current - The current declaration. |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 546 | Decl *Current; |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 547 | |
| 548 | public: |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 549 | typedef Decl* value_type; |
| 550 | typedef Decl* reference; |
| 551 | typedef Decl* pointer; |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 552 | typedef std::forward_iterator_tag iterator_category; |
| 553 | typedef std::ptrdiff_t difference_type; |
| 554 | |
| 555 | decl_iterator() : Current(0) { } |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 556 | explicit decl_iterator(Decl *C) : Current(C) { } |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 557 | |
| 558 | reference operator*() const { return Current; } |
| 559 | pointer operator->() const { return Current; } |
| 560 | |
Chris Lattner | 96f4468 | 2009-03-28 05:59:45 +0000 | [diff] [blame] | 561 | decl_iterator& operator++() { |
Chris Lattner | 244a67d | 2009-03-28 06:04:26 +0000 | [diff] [blame] | 562 | Current = Current->getNextDeclInContext(); |
Chris Lattner | 96f4468 | 2009-03-28 05:59:45 +0000 | [diff] [blame] | 563 | return *this; |
| 564 | } |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 565 | |
| 566 | decl_iterator operator++(int) { |
| 567 | decl_iterator tmp(*this); |
| 568 | ++(*this); |
| 569 | return tmp; |
| 570 | } |
| 571 | |
| 572 | friend bool operator==(decl_iterator x, decl_iterator y) { |
| 573 | return x.Current == y.Current; |
| 574 | } |
| 575 | friend bool operator!=(decl_iterator x, decl_iterator y) { |
| 576 | return x.Current != y.Current; |
| 577 | } |
| 578 | }; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 579 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 580 | /// decls_begin/decls_end - Iterate over the declarations stored in |
| 581 | /// this context. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 582 | decl_iterator decls_begin(ASTContext &Context) const; |
| 583 | decl_iterator decls_end(ASTContext &Context) const; |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 584 | bool decls_empty(ASTContext &Context) const; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 585 | |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 586 | /// specific_decl_iterator - Iterates over a subrange of |
| 587 | /// declarations stored in a DeclContext, providing only those that |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 588 | /// are of type SpecificDecl (or a class derived from it). This |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 589 | /// iterator is used, for example, to provide iteration over just |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 590 | /// the fields within a RecordDecl (with SpecificDecl = FieldDecl). |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 591 | template<typename SpecificDecl> |
| 592 | class specific_decl_iterator { |
| 593 | /// Current - The current, underlying declaration iterator, which |
Douglas Gregor | d6f0b4e | 2009-02-02 17:56:05 +0000 | [diff] [blame] | 594 | /// will either be NULL or will point to a declaration of |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 595 | /// type SpecificDecl. |
| 596 | DeclContext::decl_iterator Current; |
| 597 | |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 598 | /// SkipToNextDecl - Advances the current position up to the next |
| 599 | /// declaration of type SpecificDecl that also meets the criteria |
| 600 | /// required by Acceptable. |
| 601 | void SkipToNextDecl() { |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 602 | while (*Current && !isa<SpecificDecl>(*Current)) |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 603 | ++Current; |
| 604 | } |
| 605 | |
| 606 | public: |
| 607 | typedef SpecificDecl* value_type; |
| 608 | typedef SpecificDecl* reference; |
| 609 | typedef SpecificDecl* pointer; |
| 610 | typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type |
| 611 | difference_type; |
| 612 | typedef std::forward_iterator_tag iterator_category; |
| 613 | |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 614 | specific_decl_iterator() : Current() { } |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 615 | |
| 616 | /// specific_decl_iterator - Construct a new iterator over a |
Douglas Gregor | d6f0b4e | 2009-02-02 17:56:05 +0000 | [diff] [blame] | 617 | /// subset of the declarations the range [C, |
| 618 | /// end-of-declarations). If A is non-NULL, it is a pointer to a |
| 619 | /// member function of SpecificDecl that should return true for |
| 620 | /// all of the SpecificDecl instances that will be in the subset |
| 621 | /// of iterators. For example, if you want Objective-C instance |
| 622 | /// methods, SpecificDecl will be ObjCMethodDecl and A will be |
| 623 | /// &ObjCMethodDecl::isInstanceMethod. |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 624 | explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) { |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 625 | SkipToNextDecl(); |
| 626 | } |
| 627 | |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 628 | reference operator*() const { return cast<SpecificDecl>(*Current); } |
| 629 | pointer operator->() const { return cast<SpecificDecl>(*Current); } |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 630 | |
| 631 | specific_decl_iterator& operator++() { |
| 632 | ++Current; |
| 633 | SkipToNextDecl(); |
| 634 | return *this; |
| 635 | } |
| 636 | |
| 637 | specific_decl_iterator operator++(int) { |
| 638 | specific_decl_iterator tmp(*this); |
| 639 | ++(*this); |
| 640 | return tmp; |
| 641 | } |
| 642 | |
| 643 | friend bool |
| 644 | operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) { |
| 645 | return x.Current == y.Current; |
| 646 | } |
| 647 | |
| 648 | friend bool |
| 649 | operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) { |
| 650 | return x.Current != y.Current; |
| 651 | } |
| 652 | }; |
| 653 | |
Douglas Gregor | 669c9a2 | 2009-02-02 18:25:48 +0000 | [diff] [blame] | 654 | /// \brief Iterates over a filtered subrange of declarations stored |
| 655 | /// in a DeclContext. |
| 656 | /// |
| 657 | /// This iterator visits only those declarations that are of type |
| 658 | /// SpecificDecl (or a class derived from it) and that meet some |
| 659 | /// additional run-time criteria. This iterator is used, for |
| 660 | /// example, to provide access to the instance methods within an |
| 661 | /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and |
| 662 | /// Acceptable = ObjCMethodDecl::isInstanceMethod). |
| 663 | template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const> |
| 664 | class filtered_decl_iterator { |
| 665 | /// Current - The current, underlying declaration iterator, which |
| 666 | /// will either be NULL or will point to a declaration of |
| 667 | /// type SpecificDecl. |
| 668 | DeclContext::decl_iterator Current; |
| 669 | |
| 670 | /// SkipToNextDecl - Advances the current position up to the next |
| 671 | /// declaration of type SpecificDecl that also meets the criteria |
| 672 | /// required by Acceptable. |
| 673 | void SkipToNextDecl() { |
| 674 | while (*Current && |
| 675 | (!isa<SpecificDecl>(*Current) || |
| 676 | (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)()))) |
| 677 | ++Current; |
| 678 | } |
| 679 | |
| 680 | public: |
| 681 | typedef SpecificDecl* value_type; |
| 682 | typedef SpecificDecl* reference; |
| 683 | typedef SpecificDecl* pointer; |
| 684 | typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type |
| 685 | difference_type; |
| 686 | typedef std::forward_iterator_tag iterator_category; |
| 687 | |
| 688 | filtered_decl_iterator() : Current() { } |
| 689 | |
| 690 | /// specific_decl_iterator - Construct a new iterator over a |
| 691 | /// subset of the declarations the range [C, |
| 692 | /// end-of-declarations). If A is non-NULL, it is a pointer to a |
| 693 | /// member function of SpecificDecl that should return true for |
| 694 | /// all of the SpecificDecl instances that will be in the subset |
| 695 | /// of iterators. For example, if you want Objective-C instance |
| 696 | /// methods, SpecificDecl will be ObjCMethodDecl and A will be |
| 697 | /// &ObjCMethodDecl::isInstanceMethod. |
| 698 | explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) { |
| 699 | SkipToNextDecl(); |
| 700 | } |
| 701 | |
| 702 | reference operator*() const { return cast<SpecificDecl>(*Current); } |
| 703 | pointer operator->() const { return cast<SpecificDecl>(*Current); } |
| 704 | |
| 705 | filtered_decl_iterator& operator++() { |
| 706 | ++Current; |
| 707 | SkipToNextDecl(); |
| 708 | return *this; |
| 709 | } |
| 710 | |
| 711 | filtered_decl_iterator operator++(int) { |
| 712 | filtered_decl_iterator tmp(*this); |
| 713 | ++(*this); |
| 714 | return tmp; |
| 715 | } |
| 716 | |
| 717 | friend bool |
| 718 | operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { |
| 719 | return x.Current == y.Current; |
| 720 | } |
| 721 | |
| 722 | friend bool |
| 723 | operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) { |
| 724 | return x.Current != y.Current; |
| 725 | } |
| 726 | }; |
| 727 | |
Douglas Gregor | 40f4e69 | 2009-01-20 16:54:50 +0000 | [diff] [blame] | 728 | /// @brief Add the declaration D into this context. |
| 729 | /// |
| 730 | /// This routine should be invoked when the declaration D has first |
| 731 | /// been declared, to place D into the context where it was |
| 732 | /// (lexically) defined. Every declaration must be added to one |
| 733 | /// (and only one!) context, where it can be visited via |
| 734 | /// [decls_begin(), decls_end()). Once a declaration has been added |
| 735 | /// to its lexical context, the corresponding DeclContext owns the |
| 736 | /// declaration. |
| 737 | /// |
| 738 | /// If D is also a NamedDecl, it will be made visible within its |
| 739 | /// semantic context via makeDeclVisibleInContext. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 740 | void addDecl(ASTContext &Context, Decl *D); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 741 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 742 | /// lookup_iterator - An iterator that provides access to the results |
| 743 | /// of looking up a name within this context. |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 744 | typedef NamedDecl **lookup_iterator; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 745 | |
| 746 | /// lookup_const_iterator - An iterator that provides non-mutable |
| 747 | /// access to the results of lookup up a name within this context. |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 748 | typedef NamedDecl * const * lookup_const_iterator; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 749 | |
| 750 | typedef std::pair<lookup_iterator, lookup_iterator> lookup_result; |
| 751 | typedef std::pair<lookup_const_iterator, lookup_const_iterator> |
| 752 | lookup_const_result; |
| 753 | |
| 754 | /// lookup - Find the declarations (if any) with the given Name in |
| 755 | /// this context. Returns a range of iterators that contains all of |
Douglas Gregor | 40f4e69 | 2009-01-20 16:54:50 +0000 | [diff] [blame] | 756 | /// the declarations with this name, with object, function, member, |
| 757 | /// and enumerator names preceding any tag name. Note that this |
| 758 | /// routine will not look into parent contexts. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 759 | lookup_result lookup(ASTContext &Context, DeclarationName Name); |
| 760 | lookup_const_result lookup(ASTContext &Context, DeclarationName Name) const; |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 761 | |
Douglas Gregor | 40f4e69 | 2009-01-20 16:54:50 +0000 | [diff] [blame] | 762 | /// @brief Makes a declaration visible within this context. |
| 763 | /// |
| 764 | /// This routine makes the declaration D visible to name lookup |
| 765 | /// within this context and, if this is a transparent context, |
| 766 | /// within its parent contexts up to the first enclosing |
| 767 | /// non-transparent context. Making a declaration visible within a |
| 768 | /// context does not transfer ownership of a declaration, and a |
| 769 | /// declaration can be visible in many contexts that aren't its |
| 770 | /// lexical context. |
| 771 | /// |
| 772 | /// If D is a redeclaration of an existing declaration that is |
| 773 | /// visible from this context, as determined by |
| 774 | /// NamedDecl::declarationReplaces, the previous declaration will be |
| 775 | /// replaced with D. |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 776 | void makeDeclVisibleInContext(ASTContext &Context, NamedDecl *D); |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 777 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 778 | /// udir_iterator - Iterates through the using-directives stored |
| 779 | /// within this context. |
| 780 | typedef UsingDirectiveDecl * const * udir_iterator; |
| 781 | |
| 782 | typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range; |
| 783 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 784 | udir_iterator_range getUsingDirectives(ASTContext &Context) const; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 785 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 786 | udir_iterator using_directives_begin(ASTContext &Context) const { |
| 787 | return getUsingDirectives(Context).first; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 790 | udir_iterator using_directives_end(ASTContext &Context) const { |
| 791 | return getUsingDirectives(Context).second; |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Douglas Gregor | c2ee10d | 2009-04-07 17:20:56 +0000 | [diff] [blame] | 794 | // Low-level accessors |
| 795 | |
Douglas Gregor | c2ee10d | 2009-04-07 17:20:56 +0000 | [diff] [blame] | 796 | /// \brief Retrieve the internal representation of the lookup structure. |
Douglas Gregor | c36c540 | 2009-04-09 17:29:08 +0000 | [diff] [blame] | 797 | void* getLookupPtr() const { return LookupPtr; } |
Douglas Gregor | c2ee10d | 2009-04-07 17:20:56 +0000 | [diff] [blame] | 798 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 799 | /// \brief Whether this DeclContext has external storage containing |
| 800 | /// additional declarations that are lexically in this context. |
| 801 | bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; } |
| 802 | |
| 803 | /// \brief State whether this DeclContext has external storage for |
| 804 | /// declarations lexically in this context. |
| 805 | void setHasExternalLexicalStorage(bool ES = true) { |
| 806 | ExternalLexicalStorage = ES; |
| 807 | } |
| 808 | |
| 809 | /// \brief Whether this DeclContext has external storage containing |
| 810 | /// additional declarations that are visible in this context. |
| 811 | bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; } |
| 812 | |
| 813 | /// \brief State whether this DeclContext has external storage for |
| 814 | /// declarations visible in this context. |
| 815 | void setHasExternalVisibleStorage(bool ES = true) { |
| 816 | ExternalVisibleStorage = ES; |
| 817 | } |
| 818 | |
Argyrios Kyrtzidis | 3d7641e | 2009-02-16 14:29:28 +0000 | [diff] [blame] | 819 | static bool classof(const Decl *D); |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 820 | static bool classof(const DeclContext *D) { return true; } |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 821 | #define DECL_CONTEXT(Name) \ |
| 822 | static bool classof(const Name##Decl *D) { return true; } |
| 823 | #include "clang/AST/DeclNodes.def" |
Argyrios Kyrtzidis | 7643536 | 2008-06-10 01:32:09 +0000 | [diff] [blame] | 824 | |
| 825 | private: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 826 | void LoadLexicalDeclsFromExternalStorage(ASTContext &Context) const; |
| 827 | void LoadVisibleDeclsFromExternalStorage(ASTContext &Context) const; |
| 828 | |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 829 | void buildLookup(ASTContext &Context, DeclContext *DCtx); |
| 830 | void makeDeclVisibleInContextImpl(ASTContext &Context, NamedDecl *D); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 831 | }; |
| 832 | |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 833 | inline bool Decl::isTemplateParameter() const { |
| 834 | return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm; |
| 835 | } |
| 836 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 837 | inline bool Decl::isDefinedOutsideFunctionOrMethod() const { |
| 838 | if (getDeclContext()) |
| 839 | return !getDeclContext()->getLookupContext()->isFunctionOrMethod(); |
Chris Lattner | 96f4468 | 2009-03-28 05:59:45 +0000 | [diff] [blame] | 840 | return true; |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 841 | } |
| 842 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 843 | } // end clang. |
| 844 | |
| 845 | namespace llvm { |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 846 | |
| 847 | /// Implement a isa_impl_wrap specialization to check whether a DeclContext is |
| 848 | /// a specific Decl. |
| 849 | template<class ToTy> |
| 850 | struct isa_impl_wrap<ToTy, |
| 851 | const ::clang::DeclContext,const ::clang::DeclContext> { |
| 852 | static bool doit(const ::clang::DeclContext &Val) { |
| 853 | return ToTy::classof(::clang::Decl::castFromDeclContext(&Val)); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 854 | } |
| 855 | }; |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 856 | template<class ToTy> |
| 857 | struct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext> |
| 858 | : public isa_impl_wrap<ToTy, |
| 859 | const ::clang::DeclContext,const ::clang::DeclContext> {}; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 860 | |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 861 | /// Implement cast_convert_val for Decl -> DeclContext conversions. |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 862 | template<class FromTy> |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 863 | struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 864 | static ::clang::DeclContext &doit(const FromTy &Val) { |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 865 | return *FromTy::castToDeclContext(&Val); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 866 | } |
| 867 | }; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 868 | |
| 869 | template<class FromTy> |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 870 | struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 871 | static ::clang::DeclContext *doit(const FromTy *Val) { |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 872 | return FromTy::castToDeclContext(Val); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 873 | } |
| 874 | }; |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 875 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 876 | template<class FromTy> |
| 877 | struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { |
| 878 | static const ::clang::DeclContext &doit(const FromTy &Val) { |
| 879 | return *FromTy::castToDeclContext(&Val); |
| 880 | } |
| 881 | }; |
| 882 | |
| 883 | template<class FromTy> |
| 884 | struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { |
| 885 | static const ::clang::DeclContext *doit(const FromTy *Val) { |
| 886 | return FromTy::castToDeclContext(Val); |
| 887 | } |
| 888 | }; |
| 889 | |
Argyrios Kyrtzidis | 42220c5 | 2008-10-12 16:14:48 +0000 | [diff] [blame] | 890 | /// Implement cast_convert_val for DeclContext -> Decl conversions. |
| 891 | template<class ToTy> |
| 892 | struct cast_convert_val<ToTy, |
| 893 | const ::clang::DeclContext,const ::clang::DeclContext> { |
| 894 | static ToTy &doit(const ::clang::DeclContext &Val) { |
| 895 | return *reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(&Val)); |
| 896 | } |
| 897 | }; |
| 898 | template<class ToTy> |
| 899 | struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> |
| 900 | : public cast_convert_val<ToTy, |
| 901 | const ::clang::DeclContext,const ::clang::DeclContext> {}; |
| 902 | |
| 903 | template<class ToTy> |
| 904 | struct cast_convert_val<ToTy, |
| 905 | const ::clang::DeclContext*, const ::clang::DeclContext*> { |
| 906 | static ToTy *doit(const ::clang::DeclContext *Val) { |
| 907 | return reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(Val)); |
| 908 | } |
| 909 | }; |
| 910 | template<class ToTy> |
| 911 | struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> |
| 912 | : public cast_convert_val<ToTy, |
| 913 | const ::clang::DeclContext*,const ::clang::DeclContext*> {}; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 914 | |
| 915 | } // end namespace llvm |
| 916 | |
| 917 | #endif |