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