blob: fe091ad17bc4e143095a1d89935b6b7e9f4017cb [file] [log] [blame]
Douglas Gregor6ab35242009-04-09 21:40:53 +00001//===-- DeclBase.h - Base Classes for representing declarations -*- C++ -*-===//
Chris Lattner0ed844b2008-04-04 06:12:32 +00002//
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 Lattnerb048c982008-04-06 04:47:34 +000010// This file defines the Decl and DeclContext interfaces.
Chris Lattner0ed844b2008-04-04 06:12:32 +000011//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_DECLBASE_H
15#define LLVM_CLANG_AST_DECLBASE_H
16
17#include "clang/AST/Attr.h"
18#include "clang/AST/Type.h"
John McCallad2b8042010-01-18 23:21:37 +000019#include "clang/Basic/Specifiers.h"
Chris Lattner49f28ca2009-03-05 08:00:35 +000020#include "llvm/Support/PrettyStackTrace.h"
Chris Lattneree219fd2009-03-29 06:06:59 +000021#include "llvm/ADT/PointerUnion.h"
Chris Lattner0ed844b2008-04-04 06:12:32 +000022
23namespace clang {
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +000024class DeclContext;
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000025class TranslationUnitDecl;
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000026class NamespaceDecl;
Douglas Gregor2a3009a2009-02-03 19:21:40 +000027class UsingDirectiveDecl;
Douglas Gregor44b43212008-12-11 16:49:14 +000028class NamedDecl;
Chris Lattner0ed844b2008-04-04 06:12:32 +000029class FunctionDecl;
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000030class CXXRecordDecl;
Chris Lattnerb048c982008-04-06 04:47:34 +000031class EnumDecl;
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000032class ObjCMethodDecl;
Douglas Gregor64650af2009-02-02 23:39:07 +000033class ObjCContainerDecl;
Chris Lattner0ed844b2008-04-04 06:12:32 +000034class ObjCInterfaceDecl;
Steve Naroff0701bbb2009-01-08 17:28:14 +000035class ObjCCategoryDecl;
36class ObjCProtocolDecl;
37class ObjCImplementationDecl;
38class ObjCCategoryImplDecl;
Argyrios Kyrtzidisbfb498d2009-07-17 01:19:49 +000039class ObjCImplDecl;
Douglas Gregor074149e2009-01-05 19:45:36 +000040class LinkageSpecDecl;
Steve Naroff56ee6892008-10-08 17:01:13 +000041class BlockDecl;
Douglas Gregor44b43212008-12-11 16:49:14 +000042class DeclarationName;
Ted Kremenekeaab2062009-03-12 18:33:24 +000043class CompoundStmt;
John McCall0c01d182010-03-24 05:22:00 +000044class StoredDeclsMap;
45class DependentDiagnostic;
Chris Lattner0eda3b32009-03-29 04:32:54 +000046}
47
48namespace llvm {
49// DeclContext* is only 4-byte aligned on 32-bit systems.
50template<>
51 class PointerLikeTypeTraits<clang::DeclContext*> {
52 typedef clang::DeclContext* PT;
53public:
54 static inline void *getAsVoidPointer(PT P) { return P; }
55 static inline PT getFromVoidPointer(void *P) {
56 return static_cast<PT>(P);
57 }
58 enum { NumLowBitsAvailable = 2 };
59};
60}
61
62namespace clang {
Chris Lattner0ed844b2008-04-04 06:12:32 +000063
Mike Stump1eb44332009-09-09 15:08:12 +000064/// Decl - This represents one declaration (or definition), e.g. a variable,
65/// typedef, function, struct, etc.
Chris Lattner0ed844b2008-04-04 06:12:32 +000066///
67class Decl {
68public:
Douglas Gregor64650af2009-02-02 23:39:07 +000069 /// \brief Lists the kind of concrete classes of Decl.
Chris Lattner0ed844b2008-04-04 06:12:32 +000070 enum Kind {
Sean Hunt9a555912010-05-30 07:21:58 +000071#define DECL(DERIVED, BASE) DERIVED,
72#define ABSTRACT_DECL(DECL)
73#define DECL_RANGE(BASE, START, END) \
74 first##BASE = START, last##BASE = END,
75#define LAST_DECL_RANGE(BASE, START, END) \
76 first##BASE = START, last##BASE = END
77#include "clang/AST/DeclNodes.inc"
Chris Lattner0ed844b2008-04-04 06:12:32 +000078 };
79
Chris Lattner6ad9ac02010-05-07 21:43:38 +000080 /// \brief A placeholder type used to construct an empty shell of a
81 /// decl-derived type that will be filled in later (e.g., by some
82 /// deserialization method).
83 struct EmptyShell { };
84
John McCall0d6b1642010-04-23 18:46:30 +000085 /// IdentifierNamespace - The different namespaces in which
86 /// declarations may appear. According to C99 6.2.3, there are
87 /// four namespaces, labels, tags, members and ordinary
88 /// identifiers. C++ describes lookup completely differently:
89 /// certain lookups merely "ignore" certain kinds of declarations,
90 /// usually based on whether the declaration is of a type, etc.
91 ///
92 /// These are meant as bitmasks, so that searches in
93 /// C++ can look into the "tag" namespace during ordinary lookup.
94 ///
95 /// Decl currently provides 16 bits of IDNS bits.
Chris Lattner0ed844b2008-04-04 06:12:32 +000096 enum IdentifierNamespace {
John McCall0d6b1642010-04-23 18:46:30 +000097 /// Labels, declared with 'x:' and referenced with 'goto x'.
98 IDNS_Label = 0x0001,
99
100 /// Tags, declared with 'struct foo;' and referenced with
101 /// 'struct foo'. All tags are also types. This is what
102 /// elaborated-type-specifiers look for in C.
103 IDNS_Tag = 0x0002,
104
105 /// Types, declared with 'struct foo', typedefs, etc.
106 /// This is what elaborated-type-specifiers look for in C++,
107 /// but note that it's ill-formed to find a non-tag.
108 IDNS_Type = 0x0004,
109
110 /// Members, declared with object declarations within tag
111 /// definitions. In C, these can only be found by "qualified"
112 /// lookup in member expressions. In C++, they're found by
113 /// normal lookup.
114 IDNS_Member = 0x0008,
115
116 /// Namespaces, declared with 'namespace foo {}'.
117 /// Lookup for nested-name-specifiers find these.
118 IDNS_Namespace = 0x0010,
119
120 /// Ordinary names. In C, everything that's not a label, tag,
121 /// or member ends up here.
122 IDNS_Ordinary = 0x0020,
123
124 /// Objective C @protocol.
125 IDNS_ObjCProtocol = 0x0040,
126
127 /// This declaration is a friend function. A friend function
128 /// declaration is always in this namespace but may also be in
129 /// IDNS_Ordinary if it was previously declared.
130 IDNS_OrdinaryFriend = 0x0080,
131
132 /// This declaration is a friend class. A friend class
133 /// declaration is always in this namespace but may also be in
134 /// IDNS_Tag|IDNS_Type if it was previously declared.
135 IDNS_TagFriend = 0x0100,
136
137 /// This declaration is a using declaration. A using declaration
138 /// *introduces* a number of other declarations into the current
139 /// scope, and those declarations use the IDNS of their targets,
140 /// but the actual using declarations go in this namespace.
John McCall76d32642010-04-24 01:30:58 +0000141 IDNS_Using = 0x0200,
142
143 /// This declaration is a C++ operator declared in a non-class
144 /// context. All such operators are also in IDNS_Ordinary.
145 /// C++ lexical operator lookup looks for these.
146 IDNS_NonMemberOperator = 0x0400
Chris Lattner0ed844b2008-04-04 06:12:32 +0000147 };
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Chris Lattner0ed844b2008-04-04 06:12:32 +0000149 /// ObjCDeclQualifier - Qualifier used on types in method declarations
150 /// for remote messaging. They are meant for the arguments though and
151 /// applied to the Decls (ObjCMethodDecl and ParmVarDecl).
152 enum ObjCDeclQualifier {
153 OBJC_TQ_None = 0x0,
154 OBJC_TQ_In = 0x1,
155 OBJC_TQ_Inout = 0x2,
156 OBJC_TQ_Out = 0x4,
157 OBJC_TQ_Bycopy = 0x8,
158 OBJC_TQ_Byref = 0x10,
159 OBJC_TQ_Oneway = 0x20
160 };
Mike Stump1eb44332009-09-09 15:08:12 +0000161
Chris Lattner0ed844b2008-04-04 06:12:32 +0000162private:
Chris Lattner244a67d2009-03-28 06:04:26 +0000163 /// NextDeclInContext - The next declaration within the same lexical
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000164 /// DeclContext. These pointers form the linked list that is
165 /// traversed via DeclContext's decls_begin()/decls_end().
Chris Lattner244a67d2009-03-28 06:04:26 +0000166 Decl *NextDeclInContext;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000167
168 friend class DeclContext;
169
Chris Lattneree219fd2009-03-29 06:06:59 +0000170 struct MultipleDC {
171 DeclContext *SemanticDC;
172 DeclContext *LexicalDC;
173 };
Mike Stump1eb44332009-09-09 15:08:12 +0000174
175
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000176 /// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
177 /// For declarations that don't contain C++ scope specifiers, it contains
178 /// the DeclContext where the Decl was declared.
179 /// For declarations with C++ scope specifiers, it contains a MultipleDC*
180 /// with the context where it semantically belongs (SemanticDC) and the
181 /// context where it was lexically declared (LexicalDC).
182 /// e.g.:
183 ///
184 /// namespace A {
185 /// void f(); // SemanticDC == LexicalDC == 'namespace A'
186 /// }
187 /// void A::f(); // SemanticDC == namespace 'A'
188 /// // LexicalDC == global namespace
Chris Lattneree219fd2009-03-29 06:06:59 +0000189 llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000190
Chris Lattneree219fd2009-03-29 06:06:59 +0000191 inline bool isInSemaDC() const { return DeclCtx.is<DeclContext*>(); }
192 inline bool isOutOfSemaDC() const { return DeclCtx.is<MultipleDC*>(); }
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000193 inline MultipleDC *getMultipleDC() const {
Chris Lattneree219fd2009-03-29 06:06:59 +0000194 return DeclCtx.get<MultipleDC*>();
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000195 }
Chris Lattner10d83792009-03-27 18:46:15 +0000196 inline DeclContext *getSemanticDC() const {
Chris Lattneree219fd2009-03-29 06:06:59 +0000197 return DeclCtx.get<DeclContext*>();
Chris Lattner10d83792009-03-27 18:46:15 +0000198 }
Mike Stump1eb44332009-09-09 15:08:12 +0000199
Daniel Dunbar39d76502009-03-04 02:26:41 +0000200 /// Loc - The location that this decl.
201 SourceLocation Loc;
Mike Stump1eb44332009-09-09 15:08:12 +0000202
Chris Lattner0ed844b2008-04-04 06:12:32 +0000203 /// DeclKind - This indicates which class this is.
204 Kind DeclKind : 8;
Mike Stump1eb44332009-09-09 15:08:12 +0000205
Chris Lattner0ed844b2008-04-04 06:12:32 +0000206 /// InvalidDecl - This indicates a semantic error occurred.
207 unsigned int InvalidDecl : 1;
Mike Stump1eb44332009-09-09 15:08:12 +0000208
Chris Lattner0ed844b2008-04-04 06:12:32 +0000209 /// HasAttrs - This indicates whether the decl has attributes or not.
210 unsigned int HasAttrs : 1;
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000211
Douglas Gregor6b3945f2009-01-07 19:46:03 +0000212 /// Implicit - Whether this declaration was implicitly generated by
213 /// the implementation rather than explicitly written by the user.
214 bool Implicit : 1;
215
Douglas Gregore0762c92009-06-19 23:52:42 +0000216 /// \brief Whether this declaration was "used", meaning that a definition is
217 /// required.
218 bool Used : 1;
Douglas Gregor9cfbe482009-06-20 00:51:54 +0000219
220protected:
Douglas Gregor7d1d49d2009-10-16 20:01:17 +0000221 /// Access - Used by C++ decls for the access specifier.
222 // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
223 unsigned Access : 2;
224 friend class CXXClassMemberWrapper;
225
226 // PCHLevel - the "level" of precompiled header/AST file from which this
227 // declaration was built.
228 unsigned PCHLevel : 2;
229
Chris Lattner769dbdf2009-03-27 20:18:19 +0000230 /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
John McCall02cace72009-08-28 07:59:38 +0000231 unsigned IdentifierNamespace : 16;
Mike Stump1eb44332009-09-09 15:08:12 +0000232
Douglas Gregor9cfbe482009-06-20 00:51:54 +0000233private:
Anders Carlsson1329c272009-03-25 23:38:06 +0000234#ifndef NDEBUG
235 void CheckAccessDeclContext() const;
236#else
237 void CheckAccessDeclContext() const { }
238#endif
Mike Stump1eb44332009-09-09 15:08:12 +0000239
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000240protected:
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000241
Mike Stump1eb44332009-09-09 15:08:12 +0000242 Decl(Kind DK, DeclContext *DC, SourceLocation L)
243 : NextDeclInContext(0), DeclCtx(DC),
Daniel Dunbar39d76502009-03-04 02:26:41 +0000244 Loc(L), DeclKind(DK), InvalidDecl(0),
Douglas Gregore0762c92009-06-19 23:52:42 +0000245 HasAttrs(false), Implicit(false), Used(false),
Douglas Gregor7d1d49d2009-10-16 20:01:17 +0000246 Access(AS_none), PCHLevel(0),
247 IdentifierNamespace(getIdentifierNamespaceForKind(DK)) {
Sean Hunt9a555912010-05-30 07:21:58 +0000248 if (Decl::CollectingStats()) add(DK);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000249 }
Sam Bishop1bb19632008-04-11 18:04:39 +0000250
Chris Lattner0ed844b2008-04-04 06:12:32 +0000251 virtual ~Decl();
Sam Bishop1bb19632008-04-11 18:04:39 +0000252
253public:
Argyrios Kyrtzidis55d608c2009-06-20 08:09:14 +0000254
255 /// \brief Source range that this declaration covers.
256 virtual SourceRange getSourceRange() const {
257 return SourceRange(getLocation(), getLocation());
258 }
259 SourceLocation getLocStart() const { return getSourceRange().getBegin(); }
260 SourceLocation getLocEnd() const { return getSourceRange().getEnd(); }
261
Chris Lattner0ed844b2008-04-04 06:12:32 +0000262 SourceLocation getLocation() const { return Loc; }
263 void setLocation(SourceLocation L) { Loc = L; }
264
265 Kind getKind() const { return DeclKind; }
266 const char *getDeclKindName() const;
Mike Stump1eb44332009-09-09 15:08:12 +0000267
Chris Lattner244a67d2009-03-28 06:04:26 +0000268 Decl *getNextDeclInContext() { return NextDeclInContext; }
269 const Decl *getNextDeclInContext() const { return NextDeclInContext; }
Chris Lattner96f44682009-03-28 05:59:45 +0000270
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000271 DeclContext *getDeclContext() {
Chris Lattner10d83792009-03-27 18:46:15 +0000272 if (isInSemaDC())
273 return getSemanticDC();
274 return getMultipleDC()->SemanticDC;
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000275 }
Chris Lattner0cf2b192009-03-27 19:19:59 +0000276 const DeclContext *getDeclContext() const {
277 return const_cast<Decl*>(this)->getDeclContext();
278 }
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000279
280 TranslationUnitDecl *getTranslationUnitDecl();
281 const TranslationUnitDecl *getTranslationUnitDecl() const {
282 return const_cast<Decl*>(this)->getTranslationUnitDecl();
283 }
284
John McCall9aeed322009-10-01 00:25:31 +0000285 bool isInAnonymousNamespace() const;
286
Argyrios Kyrtzidis3708b3d2009-06-29 17:38:40 +0000287 ASTContext &getASTContext() const;
Mike Stump1eb44332009-09-09 15:08:12 +0000288
Anders Carlsson1329c272009-03-25 23:38:06 +0000289 void setAccess(AccessSpecifier AS) {
Mike Stump1eb44332009-09-09 15:08:12 +0000290 Access = AS;
Anders Carlsson1329c272009-03-25 23:38:06 +0000291 CheckAccessDeclContext();
Anders Carlssonb8547e82009-03-25 20:19:57 +0000292 }
Mike Stump1eb44332009-09-09 15:08:12 +0000293
294 AccessSpecifier getAccess() const {
Anders Carlsson1329c272009-03-25 23:38:06 +0000295 CheckAccessDeclContext();
Mike Stump1eb44332009-09-09 15:08:12 +0000296 return AccessSpecifier(Access);
Anders Carlsson1329c272009-03-25 23:38:06 +0000297 }
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000298
Chris Lattner76a642f2009-02-15 22:43:40 +0000299 bool hasAttrs() const { return HasAttrs; }
Argyrios Kyrtzidis1715bf52010-06-11 23:09:25 +0000300 void initAttrs(Attr *attrs);
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000301 void addAttr(Attr *attr);
302 const Attr *getAttrs() const {
Chris Lattner81abbdd2009-03-21 06:27:31 +0000303 if (!HasAttrs) return 0; // common case, no attributes.
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000304 return getAttrsImpl(); // Uncommon case, out of line hash lookup.
Chris Lattner81abbdd2009-03-21 06:27:31 +0000305 }
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000306 void swapAttrs(Decl *D);
307 void invalidateAttrs();
Chris Lattner0ed844b2008-04-04 06:12:32 +0000308
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000309 template<typename T> const T *getAttr() const {
310 for (const Attr *attr = getAttrs(); attr; attr = attr->getNext())
Chris Lattner0ed844b2008-04-04 06:12:32 +0000311 if (const T *V = dyn_cast<T>(attr))
312 return V;
Chris Lattner0ed844b2008-04-04 06:12:32 +0000313 return 0;
314 }
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000316 template<typename T> bool hasAttr() const {
317 return getAttr<T>() != 0;
Chris Lattner115cafc2009-04-12 20:07:59 +0000318 }
Mike Stump1eb44332009-09-09 15:08:12 +0000319
Chris Lattner0ed844b2008-04-04 06:12:32 +0000320 /// setInvalidDecl - Indicates the Decl had a semantic error. This
321 /// allows for graceful error recovery.
Douglas Gregor42738572010-03-05 00:26:45 +0000322 void setInvalidDecl(bool Invalid = true);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000323 bool isInvalidDecl() const { return (bool) InvalidDecl; }
Douglas Gregor6b3945f2009-01-07 19:46:03 +0000324
325 /// isImplicit - Indicates whether the declaration was implicitly
326 /// generated by the implementation. If false, this declaration
327 /// was written explicitly in the source code.
328 bool isImplicit() const { return Implicit; }
329 void setImplicit(bool I = true) { Implicit = I; }
Mike Stump1eb44332009-09-09 15:08:12 +0000330
Douglas Gregore0762c92009-06-19 23:52:42 +0000331 /// \brief Whether this declaration was used, meaning that a definition
332 /// is required.
Douglas Gregorc070cc62010-06-17 23:14:26 +0000333 ///
334 /// \param CheckUsedAttr When true, also consider the "used" attribute
335 /// (in addition to the "used" bit set by \c setUsed()) when determining
336 /// whether the function is used.
337 bool isUsed(bool CheckUsedAttr = true) const;
Tanya Lattner12ead492010-02-17 02:17:21 +0000338
Douglas Gregore0762c92009-06-19 23:52:42 +0000339 void setUsed(bool U = true) { Used = U; }
Mike Stump1eb44332009-09-09 15:08:12 +0000340
Douglas Gregor7d1d49d2009-10-16 20:01:17 +0000341 /// \brief Retrieve the level of precompiled header from which this
342 /// declaration was generated.
343 ///
344 /// The PCH level of a declaration describes where the declaration originated
345 /// from. A PCH level of 0 indicates that the declaration was not from a
346 /// precompiled header. A PCH level of 1 indicates that the declaration was
347 /// from a top-level precompiled header; 2 indicates that the declaration
348 /// comes from a precompiled header on which the top-level precompiled header
349 /// depends, and so on.
350 unsigned getPCHLevel() const { return PCHLevel; }
351
352 /// \brief The maximum PCH level that any declaration may have.
353 static const unsigned MaxPCHLevel = 3;
354
355 /// \brief Set the PCH level of this declaration.
356 void setPCHLevel(unsigned Level) {
357 assert(Level < MaxPCHLevel && "PCH level exceeds the maximum");
358 PCHLevel = Level;
359 }
360
Douglas Gregorcc636682009-02-17 23:15:12 +0000361 unsigned getIdentifierNamespace() const {
Chris Lattner769dbdf2009-03-27 20:18:19 +0000362 return IdentifierNamespace;
Chris Lattner0ed844b2008-04-04 06:12:32 +0000363 }
Chris Lattnerd62fdc42009-01-06 07:16:40 +0000364 bool isInIdentifierNamespace(unsigned NS) const {
365 return getIdentifierNamespace() & NS;
366 }
Chris Lattner769dbdf2009-03-27 20:18:19 +0000367 static unsigned getIdentifierNamespaceForKind(Kind DK);
368
John McCall0d6b1642010-04-23 18:46:30 +0000369 bool hasTagIdentifierNamespace() const {
370 return isTagIdentifierNamespace(getIdentifierNamespace());
371 }
372 static bool isTagIdentifierNamespace(unsigned NS) {
373 // TagDecls have Tag and Type set and may also have TagFriend.
374 return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type);
375 }
Mike Stump1eb44332009-09-09 15:08:12 +0000376
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000377 /// getLexicalDeclContext - The declaration context where this Decl was
378 /// lexically declared (LexicalDC). May be different from
379 /// getDeclContext() (SemanticDC).
380 /// e.g.:
381 ///
382 /// namespace A {
383 /// void f(); // SemanticDC == LexicalDC == 'namespace A'
384 /// }
385 /// void A::f(); // SemanticDC == namespace 'A'
386 /// // LexicalDC == global namespace
Chris Lattner10d83792009-03-27 18:46:15 +0000387 DeclContext *getLexicalDeclContext() {
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000388 if (isInSemaDC())
Chris Lattner10d83792009-03-27 18:46:15 +0000389 return getSemanticDC();
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000390 return getMultipleDC()->LexicalDC;
391 }
Chris Lattner10d83792009-03-27 18:46:15 +0000392 const DeclContext *getLexicalDeclContext() const {
393 return const_cast<Decl*>(this)->getLexicalDeclContext();
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000394 }
Argyrios Kyrtzidisf5cecfb2009-06-17 22:49:50 +0000395
Chandler Carruth8761d682010-02-21 07:08:09 +0000396 virtual bool isOutOfLine() const {
Argyrios Kyrtzidisf5cecfb2009-06-17 22:49:50 +0000397 return getLexicalDeclContext() != getDeclContext();
398 }
Mike Stump1eb44332009-09-09 15:08:12 +0000399
Douglas Gregor6ab35242009-04-09 21:40:53 +0000400 /// setDeclContext - Set both the semantic and lexical DeclContext
401 /// to DC.
402 void setDeclContext(DeclContext *DC);
403
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000404 void setLexicalDeclContext(DeclContext *DC);
405
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000406 // isDefinedOutsideFunctionOrMethod - This predicate returns true if this
407 // scoped decl is defined outside the current function or method. This is
408 // roughly global variables and functions, but also handles enums (which could
409 // be defined inside or outside a function etc).
410 bool isDefinedOutsideFunctionOrMethod() const;
411
Argyrios Kyrtzidisb57a4fe2009-07-18 00:34:07 +0000412 /// \brief Retrieves the "canonical" declaration of the given declaration.
413 virtual Decl *getCanonicalDecl() { return this; }
414 const Decl *getCanonicalDecl() const {
415 return const_cast<Decl*>(this)->getCanonicalDecl();
416 }
Argyrios Kyrtzidisfc7e2a82009-07-05 22:21:56 +0000417
Argyrios Kyrtzidisac4e3792009-07-18 08:50:48 +0000418 /// \brief Whether this particular Decl is a canonical one.
Argyrios Kyrtzidisb57a4fe2009-07-18 00:34:07 +0000419 bool isCanonicalDecl() const { return getCanonicalDecl() == this; }
Mike Stump1eb44332009-09-09 15:08:12 +0000420
Argyrios Kyrtzidis1e4bc092009-07-18 08:50:35 +0000421protected:
422 /// \brief Returns the next redeclaration or itself if this is the only decl.
423 ///
424 /// Decl subclasses that can be redeclared should override this method so that
425 /// Decl::redecl_iterator can iterate over them.
426 virtual Decl *getNextRedeclaration() { return this; }
427
428public:
429 /// \brief Iterates through all the redeclarations of the same decl.
430 class redecl_iterator {
431 /// Current - The current declaration.
432 Decl *Current;
433 Decl *Starter;
434
435 public:
436 typedef Decl* value_type;
437 typedef Decl* reference;
438 typedef Decl* pointer;
439 typedef std::forward_iterator_tag iterator_category;
440 typedef std::ptrdiff_t difference_type;
441
442 redecl_iterator() : Current(0) { }
443 explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { }
444
445 reference operator*() const { return Current; }
446 pointer operator->() const { return Current; }
447
448 redecl_iterator& operator++() {
449 assert(Current && "Advancing while iterator has reached end");
450 // Get either previous decl or latest decl.
451 Decl *Next = Current->getNextRedeclaration();
Argyrios Kyrtzidis22cbd2b2009-07-21 00:06:27 +0000452 assert(Next && "Should return next redeclaration or itself, never null!");
Argyrios Kyrtzidis1e4bc092009-07-18 08:50:35 +0000453 Current = (Next != Starter ? Next : 0);
454 return *this;
455 }
456
457 redecl_iterator operator++(int) {
458 redecl_iterator tmp(*this);
459 ++(*this);
460 return tmp;
461 }
462
Mike Stump1eb44332009-09-09 15:08:12 +0000463 friend bool operator==(redecl_iterator x, redecl_iterator y) {
Argyrios Kyrtzidis1e4bc092009-07-18 08:50:35 +0000464 return x.Current == y.Current;
465 }
Mike Stump1eb44332009-09-09 15:08:12 +0000466 friend bool operator!=(redecl_iterator x, redecl_iterator y) {
Argyrios Kyrtzidis1e4bc092009-07-18 08:50:35 +0000467 return x.Current != y.Current;
468 }
469 };
470
471 /// \brief Returns iterator for all the redeclarations of the same decl.
472 /// It will iterate at least once (when this decl is the only one).
473 redecl_iterator redecls_begin() const {
474 return redecl_iterator(const_cast<Decl*>(this));
475 }
476 redecl_iterator redecls_end() const { return redecl_iterator(); }
Argyrios Kyrtzidisfc7e2a82009-07-05 22:21:56 +0000477
Sebastian Redld3a413d2009-04-26 20:35:05 +0000478 /// getBody - If this Decl represents a declaration for a body of code,
479 /// such as a function or method definition, this method returns the
480 /// top-level Stmt* of that body. Otherwise this method returns null.
Argyrios Kyrtzidis6fb0aee2009-06-30 02:35:26 +0000481 virtual Stmt* getBody() const { return 0; }
Sebastian Redld3a413d2009-04-26 20:35:05 +0000482
483 /// getCompoundBody - Returns getBody(), dyn_casted to a CompoundStmt.
Argyrios Kyrtzidis6fb0aee2009-06-30 02:35:26 +0000484 CompoundStmt* getCompoundBody() const;
Sebastian Redld3a413d2009-04-26 20:35:05 +0000485
486 /// getBodyRBrace - Gets the right brace of the body, if a body exists.
487 /// This works whether the body is a CompoundStmt or a CXXTryStmt.
Argyrios Kyrtzidis6fb0aee2009-06-30 02:35:26 +0000488 SourceLocation getBodyRBrace() const;
Sebastian Redld3a413d2009-04-26 20:35:05 +0000489
Chris Lattner0ed844b2008-04-04 06:12:32 +0000490 // global temp stats (until we have a per-module visitor)
Sean Hunt9a555912010-05-30 07:21:58 +0000491 static void add(Kind k);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000492 static bool CollectingStats(bool Enable = false);
493 static void PrintStats();
Mike Stump1eb44332009-09-09 15:08:12 +0000494
Anders Carlsson67e33202009-06-13 00:08:58 +0000495 /// isTemplateParameter - Determines whether this declaration is a
Douglas Gregorf57172b2008-12-08 18:40:42 +0000496 /// template parameter.
497 bool isTemplateParameter() const;
Mike Stump1eb44332009-09-09 15:08:12 +0000498
Anders Carlsson67e33202009-06-13 00:08:58 +0000499 /// isTemplateParameter - Determines whether this declaration is a
500 /// template parameter pack.
501 bool isTemplateParameterPack() const;
Douglas Gregorf57172b2008-12-08 18:40:42 +0000502
Douglas Gregore53060f2009-06-25 22:08:12 +0000503 /// \brief Whether this declaration is a function or function template.
504 bool isFunctionOrFunctionTemplate() const;
John McCall02cace72009-08-28 07:59:38 +0000505
506 /// \brief Changes the namespace of this declaration to reflect that it's
507 /// the object of a friend declaration.
508 ///
509 /// These declarations appear in the lexical context of the friending
510 /// class, but in the semantic context of the actual entity. This property
511 /// applies only to a specific decl object; other redeclarations of the
512 /// same entity may not (and probably don't) share this property.
513 void setObjectOfFriendDecl(bool PreviouslyDeclared) {
514 unsigned OldNS = IdentifierNamespace;
John McCallb0cb0222010-03-27 05:57:59 +0000515 assert((OldNS & (IDNS_Tag | IDNS_Ordinary |
516 IDNS_TagFriend | IDNS_OrdinaryFriend)) &&
517 "namespace includes neither ordinary nor tag");
John McCall0d6b1642010-04-23 18:46:30 +0000518 assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type |
John McCallb0cb0222010-03-27 05:57:59 +0000519 IDNS_TagFriend | IDNS_OrdinaryFriend)) &&
520 "namespace includes other than ordinary or tag");
John McCall02cace72009-08-28 07:59:38 +0000521
John McCallb0cb0222010-03-27 05:57:59 +0000522 IdentifierNamespace = 0;
523 if (OldNS & (IDNS_Tag | IDNS_TagFriend)) {
John McCall02cace72009-08-28 07:59:38 +0000524 IdentifierNamespace |= IDNS_TagFriend;
John McCall0d6b1642010-04-23 18:46:30 +0000525 if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Tag | IDNS_Type;
John McCallb0cb0222010-03-27 05:57:59 +0000526 }
527
528 if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend)) {
John McCall02cace72009-08-28 07:59:38 +0000529 IdentifierNamespace |= IDNS_OrdinaryFriend;
John McCallb0cb0222010-03-27 05:57:59 +0000530 if (PreviouslyDeclared) IdentifierNamespace |= IDNS_Ordinary;
531 }
John McCall02cace72009-08-28 07:59:38 +0000532 }
533
534 enum FriendObjectKind {
535 FOK_None, // not a friend object
536 FOK_Declared, // a friend of a previously-declared entity
537 FOK_Undeclared // a friend of a previously-undeclared entity
538 };
539
540 /// \brief Determines whether this declaration is the object of a
541 /// friend declaration and, if so, what kind.
542 ///
543 /// There is currently no direct way to find the associated FriendDecl.
544 FriendObjectKind getFriendObjectKind() const {
545 unsigned mask
546 = (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend));
547 if (!mask) return FOK_None;
Anders Carlsson255d6412009-09-13 23:59:13 +0000548 return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ?
549 FOK_Declared : FOK_Undeclared);
John McCall02cace72009-08-28 07:59:38 +0000550 }
Mike Stump1eb44332009-09-09 15:08:12 +0000551
John McCall76d32642010-04-24 01:30:58 +0000552 /// Specifies that this declaration is a C++ overloaded non-member.
553 void setNonMemberOperator() {
554 assert(getKind() == Function || getKind() == FunctionTemplate);
555 assert((IdentifierNamespace & IDNS_Ordinary) &&
556 "visible non-member operators should be in ordinary namespace");
557 IdentifierNamespace |= IDNS_NonMemberOperator;
558 }
559
Chris Lattner0ed844b2008-04-04 06:12:32 +0000560 // Implement isa/cast/dyncast/etc.
561 static bool classof(const Decl *) { return true; }
John McCall80cd64a2010-01-29 01:45:37 +0000562 static bool classofKind(Kind K) { return true; }
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +0000563 static DeclContext *castToDeclContext(const Decl *);
564 static Decl *castFromDeclContext(const DeclContext *);
Mike Stump1eb44332009-09-09 15:08:12 +0000565
Sam Bishopbb45c512008-04-11 15:01:25 +0000566 /// Destroy - Call destructors and release memory.
Ted Kremenek27f8a282008-05-20 00:43:19 +0000567 virtual void Destroy(ASTContext& C);
Sam Bishopbb45c512008-04-11 15:01:25 +0000568
Anders Carlssonf88df862009-09-26 21:58:53 +0000569 void print(llvm::raw_ostream &Out, unsigned Indentation = 0) const;
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000570 void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Anders Carlssonf88df862009-09-26 21:58:53 +0000571 unsigned Indentation = 0) const;
Eli Friedman42f42c02009-05-30 04:20:30 +0000572 static void printGroup(Decl** Begin, unsigned NumDecls,
Argyrios Kyrtzidisf1d60ea2009-06-30 02:35:04 +0000573 llvm::raw_ostream &Out, const PrintingPolicy &Policy,
Eli Friedman42f42c02009-05-30 04:20:30 +0000574 unsigned Indentation = 0);
Anders Carlssonf88df862009-09-26 21:58:53 +0000575 void dump() const;
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +0000576
Chris Lattner81abbdd2009-03-21 06:27:31 +0000577private:
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000578 const Attr *getAttrsImpl() const;
Chris Lattner81abbdd2009-03-21 06:27:31 +0000579
Chris Lattner0ed844b2008-04-04 06:12:32 +0000580};
581
Chris Lattner49f28ca2009-03-05 08:00:35 +0000582/// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when
583/// doing something to a specific decl.
584class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry {
Daniel Dunbarc5236562009-11-21 09:05:59 +0000585 const Decl *TheDecl;
Chris Lattner49f28ca2009-03-05 08:00:35 +0000586 SourceLocation Loc;
587 SourceManager &SM;
588 const char *Message;
589public:
Daniel Dunbarc5236562009-11-21 09:05:59 +0000590 PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L,
Chris Lattner49f28ca2009-03-05 08:00:35 +0000591 SourceManager &sm, const char *Msg)
592 : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {}
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Chris Lattner49f28ca2009-03-05 08:00:35 +0000594 virtual void print(llvm::raw_ostream &OS) const;
Mike Stump1eb44332009-09-09 15:08:12 +0000595};
596
Chris Lattner49f28ca2009-03-05 08:00:35 +0000597
Chris Lattnerb048c982008-04-06 04:47:34 +0000598/// DeclContext - This is used only as base class of specific decl types that
Argyrios Kyrtzidis1ad4dd72009-02-16 14:28:33 +0000599/// can act as declaration contexts. These decls are (only the top classes
600/// that directly derive from DeclContext are mentioned, not their subclasses):
Chris Lattner0ed844b2008-04-04 06:12:32 +0000601///
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000602/// TranslationUnitDecl
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000603/// NamespaceDecl
Chris Lattner0ed844b2008-04-04 06:12:32 +0000604/// FunctionDecl
Argyrios Kyrtzidis1ad4dd72009-02-16 14:28:33 +0000605/// TagDecl
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000606/// ObjCMethodDecl
Argyrios Kyrtzidis1ad4dd72009-02-16 14:28:33 +0000607/// ObjCContainerDecl
Douglas Gregor074149e2009-01-05 19:45:36 +0000608/// LinkageSpecDecl
Steve Naroff56ee6892008-10-08 17:01:13 +0000609/// BlockDecl
Argyrios Kyrtzidis1ad4dd72009-02-16 14:28:33 +0000610///
Chris Lattnerb048c982008-04-06 04:47:34 +0000611class DeclContext {
Chris Lattner0ed844b2008-04-04 06:12:32 +0000612 /// DeclKind - This indicates which class this is.
613 Decl::Kind DeclKind : 8;
614
Douglas Gregor2cf26342009-04-09 22:27:44 +0000615 /// \brief Whether this declaration context also has some external
616 /// storage that contains additional declarations that are lexically
617 /// part of this context.
618 mutable bool ExternalLexicalStorage : 1;
619
620 /// \brief Whether this declaration context also has some external
621 /// storage that contains additional declarations that are visible
622 /// in this context.
623 mutable bool ExternalVisibleStorage : 1;
624
Douglas Gregorc36c5402009-04-09 17:29:08 +0000625 /// \brief Pointer to the data structure used to lookup declarations
John McCall0c01d182010-03-24 05:22:00 +0000626 /// within this context (or a DependentStoredDeclsMap if this is a
627 /// dependent context).
628 mutable StoredDeclsMap *LookupPtr;
Douglas Gregor44b43212008-12-11 16:49:14 +0000629
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000630 /// FirstDecl - The first declaration stored within this declaration
631 /// context.
Douglas Gregor2cf26342009-04-09 22:27:44 +0000632 mutable Decl *FirstDecl;
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000633
634 /// LastDecl - The last declaration stored within this declaration
635 /// context. FIXME: We could probably cache this value somewhere
636 /// outside of the DeclContext, to reduce the size of DeclContext by
637 /// another pointer.
Douglas Gregor2cf26342009-04-09 22:27:44 +0000638 mutable Decl *LastDecl;
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000639
John McCall76bd1f32010-06-01 09:23:16 +0000640 friend class ExternalASTSource;
641
Chris Lattner0ed844b2008-04-04 06:12:32 +0000642protected:
Mike Stump1eb44332009-09-09 15:08:12 +0000643 DeclContext(Decl::Kind K)
Douglas Gregor2cf26342009-04-09 22:27:44 +0000644 : DeclKind(K), ExternalLexicalStorage(false),
Mike Stump1eb44332009-09-09 15:08:12 +0000645 ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0),
Douglas Gregor2cf26342009-04-09 22:27:44 +0000646 LastDecl(0) { }
Douglas Gregor44b43212008-12-11 16:49:14 +0000647
648 void DestroyDecls(ASTContext &C);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000649
650public:
Douglas Gregor44b43212008-12-11 16:49:14 +0000651 ~DeclContext();
652
Argyrios Kyrtzidis9b9ca012009-01-13 13:11:58 +0000653 Decl::Kind getDeclKind() const {
654 return DeclKind;
655 }
Steve Naroff0a473932009-01-20 19:53:53 +0000656 const char *getDeclKindName() const;
Argyrios Kyrtzidis9b9ca012009-01-13 13:11:58 +0000657
Argyrios Kyrtzidis305ec422009-02-17 20:26:05 +0000658 /// getParent - Returns the containing DeclContext.
Chris Lattner0cf2b192009-03-27 19:19:59 +0000659 DeclContext *getParent() {
Argyrios Kyrtzidis305ec422009-02-17 20:26:05 +0000660 return cast<Decl>(this)->getDeclContext();
661 }
Chris Lattner0cf2b192009-03-27 19:19:59 +0000662 const DeclContext *getParent() const {
663 return const_cast<DeclContext*>(this)->getParent();
Argyrios Kyrtzidisd2595ec2008-10-12 18:40:01 +0000664 }
Mike Stump1eb44332009-09-09 15:08:12 +0000665
Argyrios Kyrtzidis77407b82008-11-19 18:01:13 +0000666 /// getLexicalParent - Returns the containing lexical DeclContext. May be
Douglas Gregor44b43212008-12-11 16:49:14 +0000667 /// different from getParent, e.g.:
668 ///
669 /// namespace A {
670 /// struct S;
671 /// }
672 /// struct A::S {}; // getParent() == namespace 'A'
Argyrios Kyrtzidis77407b82008-11-19 18:01:13 +0000673 /// // getLexicalParent() == translation unit
674 ///
Argyrios Kyrtzidis77407b82008-11-19 18:01:13 +0000675 DeclContext *getLexicalParent() {
Chris Lattner0cf2b192009-03-27 19:19:59 +0000676 return cast<Decl>(this)->getLexicalDeclContext();
Argyrios Kyrtzidis77407b82008-11-19 18:01:13 +0000677 }
Chris Lattner0cf2b192009-03-27 19:19:59 +0000678 const DeclContext *getLexicalParent() const {
679 return const_cast<DeclContext*>(this)->getLexicalParent();
Mike Stump1eb44332009-09-09 15:08:12 +0000680 }
Argyrios Kyrtzidis048f30a2009-06-30 02:35:38 +0000681
Douglas Gregore942bbe2009-09-10 16:57:35 +0000682 DeclContext *getLookupParent();
683
684 const DeclContext *getLookupParent() const {
685 return const_cast<DeclContext*>(this)->getLookupParent();
686 }
687
Argyrios Kyrtzidis048f30a2009-06-30 02:35:38 +0000688 ASTContext &getParentASTContext() const {
689 return cast<Decl>(this)->getASTContext();
690 }
691
Chris Lattner0ed844b2008-04-04 06:12:32 +0000692 bool isFunctionOrMethod() const {
693 switch (DeclKind) {
Chris Lattner0cf2b192009-03-27 19:19:59 +0000694 case Decl::Block:
695 case Decl::ObjCMethod:
696 return true;
697 default:
Sean Hunt9a555912010-05-30 07:21:58 +0000698 return DeclKind >= Decl::firstFunction && DeclKind <= Decl::lastFunction;
Chris Lattner0ed844b2008-04-04 06:12:32 +0000699 }
700 }
701
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +0000702 bool isFileContext() const {
703 return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace;
704 }
705
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000706 bool isTranslationUnit() const {
707 return DeclKind == Decl::TranslationUnit;
708 }
709
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000710 bool isRecord() const {
Sean Hunt9a555912010-05-30 07:21:58 +0000711 return DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord;
Argyrios Kyrtzidisc7ed9c62008-11-07 22:02:30 +0000712 }
713
Douglas Gregor44b43212008-12-11 16:49:14 +0000714 bool isNamespace() const {
715 return DeclKind == Decl::Namespace;
716 }
717
Douglas Gregorbc221632009-05-28 16:34:51 +0000718 /// \brief Determines whether this context is dependent on a
719 /// template parameter.
720 bool isDependentContext() const;
721
Douglas Gregor074149e2009-01-05 19:45:36 +0000722 /// isTransparentContext - Determines whether this context is a
723 /// "transparent" context, meaning that the members declared in this
724 /// context are semantically declared in the nearest enclosing
725 /// non-transparent (opaque) context but are lexically declared in
726 /// this context. For example, consider the enumerators of an
Mike Stump1eb44332009-09-09 15:08:12 +0000727 /// enumeration type:
Douglas Gregor074149e2009-01-05 19:45:36 +0000728 /// @code
729 /// enum E {
Mike Stump1eb44332009-09-09 15:08:12 +0000730 /// Val1
Douglas Gregor074149e2009-01-05 19:45:36 +0000731 /// };
732 /// @endcode
733 /// Here, E is a transparent context, so its enumerator (Val1) will
734 /// appear (semantically) that it is in the same context of E.
735 /// Examples of transparent contexts include: enumerations (except for
736 /// C++0x scoped enums), C++ linkage specifications, and C++0x
737 /// inline namespaces.
738 bool isTransparentContext() const;
739
Douglas Gregor61481da2009-09-01 17:22:34 +0000740 /// \brief Determine whether this declaration context is equivalent
741 /// to the declaration context DC.
742 bool Equals(DeclContext *DC) {
Douglas Gregordbdf5e72010-03-15 15:26:48 +0000743 return DC && this->getPrimaryContext() == DC->getPrimaryContext();
Douglas Gregor61481da2009-09-01 17:22:34 +0000744 }
Mike Stump1eb44332009-09-09 15:08:12 +0000745
Douglas Gregor6dd38da2009-08-27 06:03:53 +0000746 /// \brief Determine whether this declaration context encloses the
747 /// declaration context DC.
748 bool Encloses(DeclContext *DC);
Argyrios Kyrtzidisef6e6472008-11-08 17:17:31 +0000749
Douglas Gregor44b43212008-12-11 16:49:14 +0000750 /// getPrimaryContext - There may be many different
751 /// declarations of the same entity (including forward declarations
752 /// of classes, multiple definitions of namespaces, etc.), each with
753 /// a different set of declarations. This routine returns the
754 /// "primary" DeclContext structure, which will contain the
755 /// information needed to perform name lookup into this context.
Steve Naroff0701bbb2009-01-08 17:28:14 +0000756 DeclContext *getPrimaryContext();
John McCall0c01d182010-03-24 05:22:00 +0000757 const DeclContext *getPrimaryContext() const {
758 return const_cast<DeclContext*>(this)->getPrimaryContext();
759 }
Douglas Gregor44b43212008-12-11 16:49:14 +0000760
Douglas Gregorce356072009-01-06 23:51:29 +0000761 /// getLookupContext - Retrieve the innermost non-transparent
762 /// context of this context, which corresponds to the innermost
763 /// location from which name lookup can find the entities in this
764 /// context.
Chris Lattner0cf2b192009-03-27 19:19:59 +0000765 DeclContext *getLookupContext();
766 const DeclContext *getLookupContext() const {
767 return const_cast<DeclContext *>(this)->getLookupContext();
Douglas Gregor17a9b9e2009-01-07 02:48:43 +0000768 }
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Douglas Gregor88b70942009-02-25 22:02:03 +0000770 /// \brief Retrieve the nearest enclosing namespace context.
771 DeclContext *getEnclosingNamespaceContext();
772 const DeclContext *getEnclosingNamespaceContext() const {
773 return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext();
774 }
775
Douglas Gregor44b43212008-12-11 16:49:14 +0000776 /// getNextContext - If this is a DeclContext that may have other
777 /// DeclContexts that are semantically connected but syntactically
778 /// different, such as C++ namespaces, this routine retrieves the
779 /// next DeclContext in the link. Iteration through the chain of
780 /// DeclContexts should begin at the primary DeclContext and
781 /// continue until this function returns NULL. For example, given:
782 /// @code
783 /// namespace N {
784 /// int x;
785 /// }
786 /// namespace N {
787 /// int y;
788 /// }
789 /// @endcode
790 /// The first occurrence of namespace N will be the primary
791 /// DeclContext. Its getNextContext will return the second
792 /// occurrence of namespace N.
793 DeclContext *getNextContext();
794
795 /// decl_iterator - Iterates through the declarations stored
796 /// within this context.
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000797 class decl_iterator {
798 /// Current - The current declaration.
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000799 Decl *Current;
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000800
801 public:
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000802 typedef Decl* value_type;
803 typedef Decl* reference;
804 typedef Decl* pointer;
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000805 typedef std::forward_iterator_tag iterator_category;
806 typedef std::ptrdiff_t difference_type;
807
808 decl_iterator() : Current(0) { }
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000809 explicit decl_iterator(Decl *C) : Current(C) { }
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000810
811 reference operator*() const { return Current; }
812 pointer operator->() const { return Current; }
813
Chris Lattner96f44682009-03-28 05:59:45 +0000814 decl_iterator& operator++() {
Chris Lattner244a67d2009-03-28 06:04:26 +0000815 Current = Current->getNextDeclInContext();
Chris Lattner96f44682009-03-28 05:59:45 +0000816 return *this;
817 }
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000818
819 decl_iterator operator++(int) {
820 decl_iterator tmp(*this);
821 ++(*this);
822 return tmp;
823 }
824
Mike Stump1eb44332009-09-09 15:08:12 +0000825 friend bool operator==(decl_iterator x, decl_iterator y) {
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000826 return x.Current == y.Current;
827 }
Mike Stump1eb44332009-09-09 15:08:12 +0000828 friend bool operator!=(decl_iterator x, decl_iterator y) {
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000829 return x.Current != y.Current;
830 }
831 };
Douglas Gregor44b43212008-12-11 16:49:14 +0000832
Douglas Gregor44b43212008-12-11 16:49:14 +0000833 /// decls_begin/decls_end - Iterate over the declarations stored in
Mike Stump1eb44332009-09-09 15:08:12 +0000834 /// this context.
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000835 decl_iterator decls_begin() const;
836 decl_iterator decls_end() const;
837 bool decls_empty() const;
Douglas Gregor44b43212008-12-11 16:49:14 +0000838
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000839 /// specific_decl_iterator - Iterates over a subrange of
840 /// declarations stored in a DeclContext, providing only those that
Douglas Gregor669c9a22009-02-02 18:25:48 +0000841 /// are of type SpecificDecl (or a class derived from it). This
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000842 /// iterator is used, for example, to provide iteration over just
Douglas Gregor669c9a22009-02-02 18:25:48 +0000843 /// the fields within a RecordDecl (with SpecificDecl = FieldDecl).
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000844 template<typename SpecificDecl>
845 class specific_decl_iterator {
846 /// Current - The current, underlying declaration iterator, which
Douglas Gregord6f0b4e2009-02-02 17:56:05 +0000847 /// will either be NULL or will point to a declaration of
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000848 /// type SpecificDecl.
849 DeclContext::decl_iterator Current;
Mike Stump1eb44332009-09-09 15:08:12 +0000850
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000851 /// SkipToNextDecl - Advances the current position up to the next
852 /// declaration of type SpecificDecl that also meets the criteria
853 /// required by Acceptable.
854 void SkipToNextDecl() {
Douglas Gregor669c9a22009-02-02 18:25:48 +0000855 while (*Current && !isa<SpecificDecl>(*Current))
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000856 ++Current;
857 }
858
859 public:
860 typedef SpecificDecl* value_type;
861 typedef SpecificDecl* reference;
862 typedef SpecificDecl* pointer;
863 typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
864 difference_type;
865 typedef std::forward_iterator_tag iterator_category;
866
Douglas Gregor669c9a22009-02-02 18:25:48 +0000867 specific_decl_iterator() : Current() { }
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000868
869 /// specific_decl_iterator - Construct a new iterator over a
Douglas Gregord6f0b4e2009-02-02 17:56:05 +0000870 /// subset of the declarations the range [C,
871 /// end-of-declarations). If A is non-NULL, it is a pointer to a
872 /// member function of SpecificDecl that should return true for
873 /// all of the SpecificDecl instances that will be in the subset
874 /// of iterators. For example, if you want Objective-C instance
875 /// methods, SpecificDecl will be ObjCMethodDecl and A will be
876 /// &ObjCMethodDecl::isInstanceMethod.
Douglas Gregor669c9a22009-02-02 18:25:48 +0000877 explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) {
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000878 SkipToNextDecl();
879 }
880
Douglas Gregor6037fcb2009-01-09 19:42:16 +0000881 reference operator*() const { return cast<SpecificDecl>(*Current); }
882 pointer operator->() const { return cast<SpecificDecl>(*Current); }
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000883
884 specific_decl_iterator& operator++() {
885 ++Current;
886 SkipToNextDecl();
887 return *this;
888 }
889
890 specific_decl_iterator operator++(int) {
891 specific_decl_iterator tmp(*this);
892 ++(*this);
893 return tmp;
894 }
Mike Stump1eb44332009-09-09 15:08:12 +0000895
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000896 friend bool
897 operator==(const specific_decl_iterator& x, const specific_decl_iterator& y) {
898 return x.Current == y.Current;
899 }
Mike Stump1eb44332009-09-09 15:08:12 +0000900
901 friend bool
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000902 operator!=(const specific_decl_iterator& x, const specific_decl_iterator& y) {
903 return x.Current != y.Current;
904 }
905 };
906
Douglas Gregor669c9a22009-02-02 18:25:48 +0000907 /// \brief Iterates over a filtered subrange of declarations stored
908 /// in a DeclContext.
909 ///
910 /// This iterator visits only those declarations that are of type
911 /// SpecificDecl (or a class derived from it) and that meet some
912 /// additional run-time criteria. This iterator is used, for
913 /// example, to provide access to the instance methods within an
914 /// Objective-C interface (with SpecificDecl = ObjCMethodDecl and
915 /// Acceptable = ObjCMethodDecl::isInstanceMethod).
916 template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const>
917 class filtered_decl_iterator {
918 /// Current - The current, underlying declaration iterator, which
919 /// will either be NULL or will point to a declaration of
920 /// type SpecificDecl.
921 DeclContext::decl_iterator Current;
Mike Stump1eb44332009-09-09 15:08:12 +0000922
Douglas Gregor669c9a22009-02-02 18:25:48 +0000923 /// SkipToNextDecl - Advances the current position up to the next
924 /// declaration of type SpecificDecl that also meets the criteria
925 /// required by Acceptable.
926 void SkipToNextDecl() {
927 while (*Current &&
928 (!isa<SpecificDecl>(*Current) ||
929 (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)())))
930 ++Current;
931 }
932
933 public:
934 typedef SpecificDecl* value_type;
935 typedef SpecificDecl* reference;
936 typedef SpecificDecl* pointer;
937 typedef std::iterator_traits<DeclContext::decl_iterator>::difference_type
938 difference_type;
939 typedef std::forward_iterator_tag iterator_category;
940
941 filtered_decl_iterator() : Current() { }
942
943 /// specific_decl_iterator - Construct a new iterator over a
944 /// subset of the declarations the range [C,
945 /// end-of-declarations). If A is non-NULL, it is a pointer to a
946 /// member function of SpecificDecl that should return true for
947 /// all of the SpecificDecl instances that will be in the subset
948 /// of iterators. For example, if you want Objective-C instance
949 /// methods, SpecificDecl will be ObjCMethodDecl and A will be
950 /// &ObjCMethodDecl::isInstanceMethod.
951 explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) {
952 SkipToNextDecl();
953 }
954
955 reference operator*() const { return cast<SpecificDecl>(*Current); }
956 pointer operator->() const { return cast<SpecificDecl>(*Current); }
957
958 filtered_decl_iterator& operator++() {
959 ++Current;
960 SkipToNextDecl();
961 return *this;
962 }
963
964 filtered_decl_iterator operator++(int) {
965 filtered_decl_iterator tmp(*this);
966 ++(*this);
967 return tmp;
968 }
Mike Stump1eb44332009-09-09 15:08:12 +0000969
Douglas Gregor669c9a22009-02-02 18:25:48 +0000970 friend bool
971 operator==(const filtered_decl_iterator& x, const filtered_decl_iterator& y) {
972 return x.Current == y.Current;
973 }
Mike Stump1eb44332009-09-09 15:08:12 +0000974
975 friend bool
Douglas Gregor669c9a22009-02-02 18:25:48 +0000976 operator!=(const filtered_decl_iterator& x, const filtered_decl_iterator& y) {
977 return x.Current != y.Current;
978 }
979 };
980
Douglas Gregor40f4e692009-01-20 16:54:50 +0000981 /// @brief Add the declaration D into this context.
982 ///
983 /// This routine should be invoked when the declaration D has first
984 /// been declared, to place D into the context where it was
985 /// (lexically) defined. Every declaration must be added to one
986 /// (and only one!) context, where it can be visited via
987 /// [decls_begin(), decls_end()). Once a declaration has been added
988 /// to its lexical context, the corresponding DeclContext owns the
989 /// declaration.
990 ///
991 /// If D is also a NamedDecl, it will be made visible within its
992 /// semantic context via makeDeclVisibleInContext.
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000993 void addDecl(Decl *D);
Douglas Gregor44b43212008-12-11 16:49:14 +0000994
John McCall3f9a8a62009-08-11 06:59:38 +0000995 /// @brief Add the declaration D to this context without modifying
996 /// any lookup tables.
997 ///
998 /// This is useful for some operations in dependent contexts where
999 /// the semantic context might not be dependent; this basically
1000 /// only happens with friends.
1001 void addHiddenDecl(Decl *D);
1002
John McCall9f54ad42009-12-10 09:41:52 +00001003 /// @brief Removes a declaration from this context.
1004 void removeDecl(Decl *D);
1005
Douglas Gregor44b43212008-12-11 16:49:14 +00001006 /// lookup_iterator - An iterator that provides access to the results
1007 /// of looking up a name within this context.
Douglas Gregor4afa39d2009-01-20 01:17:11 +00001008 typedef NamedDecl **lookup_iterator;
Douglas Gregor44b43212008-12-11 16:49:14 +00001009
1010 /// lookup_const_iterator - An iterator that provides non-mutable
1011 /// access to the results of lookup up a name within this context.
Douglas Gregor4afa39d2009-01-20 01:17:11 +00001012 typedef NamedDecl * const * lookup_const_iterator;
Douglas Gregor44b43212008-12-11 16:49:14 +00001013
1014 typedef std::pair<lookup_iterator, lookup_iterator> lookup_result;
1015 typedef std::pair<lookup_const_iterator, lookup_const_iterator>
1016 lookup_const_result;
1017
1018 /// lookup - Find the declarations (if any) with the given Name in
1019 /// this context. Returns a range of iterators that contains all of
Douglas Gregor40f4e692009-01-20 16:54:50 +00001020 /// the declarations with this name, with object, function, member,
1021 /// and enumerator names preceding any tag name. Note that this
1022 /// routine will not look into parent contexts.
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001023 lookup_result lookup(DeclarationName Name);
1024 lookup_const_result lookup(DeclarationName Name) const;
Douglas Gregor44b43212008-12-11 16:49:14 +00001025
Douglas Gregor40f4e692009-01-20 16:54:50 +00001026 /// @brief Makes a declaration visible within this context.
1027 ///
1028 /// This routine makes the declaration D visible to name lookup
1029 /// within this context and, if this is a transparent context,
1030 /// within its parent contexts up to the first enclosing
1031 /// non-transparent context. Making a declaration visible within a
1032 /// context does not transfer ownership of a declaration, and a
1033 /// declaration can be visible in many contexts that aren't its
1034 /// lexical context.
1035 ///
1036 /// If D is a redeclaration of an existing declaration that is
1037 /// visible from this context, as determined by
1038 /// NamedDecl::declarationReplaces, the previous declaration will be
1039 /// replaced with D.
John McCallab88d972009-08-31 22:39:49 +00001040 ///
1041 /// @param Recoverable true if it's okay to not add this decl to
1042 /// the lookup tables because it can be easily recovered by walking
1043 /// the declaration chains.
1044 void makeDeclVisibleInContext(NamedDecl *D, bool Recoverable = true);
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +00001045
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001046 /// udir_iterator - Iterates through the using-directives stored
1047 /// within this context.
1048 typedef UsingDirectiveDecl * const * udir_iterator;
Mike Stump1eb44332009-09-09 15:08:12 +00001049
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001050 typedef std::pair<udir_iterator, udir_iterator> udir_iterator_range;
1051
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001052 udir_iterator_range getUsingDirectives() const;
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001053
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001054 udir_iterator using_directives_begin() const {
1055 return getUsingDirectives().first;
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001056 }
1057
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001058 udir_iterator using_directives_end() const {
1059 return getUsingDirectives().second;
Douglas Gregor2a3009a2009-02-03 19:21:40 +00001060 }
1061
John McCall0c01d182010-03-24 05:22:00 +00001062 // These are all defined in DependentDiagnostic.h.
1063 class ddiag_iterator;
1064 inline ddiag_iterator ddiag_begin() const;
1065 inline ddiag_iterator ddiag_end() const;
1066
Douglas Gregorc2ee10d2009-04-07 17:20:56 +00001067 // Low-level accessors
1068
Douglas Gregorc2ee10d2009-04-07 17:20:56 +00001069 /// \brief Retrieve the internal representation of the lookup structure.
John McCall0c01d182010-03-24 05:22:00 +00001070 StoredDeclsMap* getLookupPtr() const { return LookupPtr; }
Douglas Gregorc2ee10d2009-04-07 17:20:56 +00001071
Douglas Gregor2cf26342009-04-09 22:27:44 +00001072 /// \brief Whether this DeclContext has external storage containing
1073 /// additional declarations that are lexically in this context.
1074 bool hasExternalLexicalStorage() const { return ExternalLexicalStorage; }
1075
1076 /// \brief State whether this DeclContext has external storage for
1077 /// declarations lexically in this context.
Mike Stump1eb44332009-09-09 15:08:12 +00001078 void setHasExternalLexicalStorage(bool ES = true) {
1079 ExternalLexicalStorage = ES;
Douglas Gregor2cf26342009-04-09 22:27:44 +00001080 }
1081
1082 /// \brief Whether this DeclContext has external storage containing
1083 /// additional declarations that are visible in this context.
1084 bool hasExternalVisibleStorage() const { return ExternalVisibleStorage; }
1085
1086 /// \brief State whether this DeclContext has external storage for
1087 /// declarations visible in this context.
Mike Stump1eb44332009-09-09 15:08:12 +00001088 void setHasExternalVisibleStorage(bool ES = true) {
1089 ExternalVisibleStorage = ES;
Douglas Gregor2cf26342009-04-09 22:27:44 +00001090 }
1091
Argyrios Kyrtzidis3d7641e2009-02-16 14:29:28 +00001092 static bool classof(const Decl *D);
Chris Lattnerb048c982008-04-06 04:47:34 +00001093 static bool classof(const DeclContext *D) { return true; }
Sean Hunt9a555912010-05-30 07:21:58 +00001094#define DECL(NAME, BASE)
1095#define DECL_CONTEXT(NAME) \
1096 static bool classof(const NAME##Decl *D) { return true; }
1097#include "clang/AST/DeclNodes.inc"
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +00001098
Anders Carlsson84834432009-12-14 00:51:04 +00001099 void dumpDeclContext() const;
Anders Carlsson2b7d8dd2009-12-09 17:27:46 +00001100
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +00001101private:
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001102 void LoadLexicalDeclsFromExternalStorage() const;
1103 void LoadVisibleDeclsFromExternalStorage() const;
Douglas Gregor2cf26342009-04-09 22:27:44 +00001104
John McCall0c01d182010-03-24 05:22:00 +00001105 friend class DependentDiagnostic;
1106 StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const;
1107
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001108 void buildLookup(DeclContext *DCtx);
1109 void makeDeclVisibleInContextImpl(NamedDecl *D);
Chris Lattner0ed844b2008-04-04 06:12:32 +00001110};
1111
Douglas Gregorf57172b2008-12-08 18:40:42 +00001112inline bool Decl::isTemplateParameter() const {
Douglas Gregor79c22782010-01-16 20:21:20 +00001113 return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm ||
1114 getKind() == TemplateTemplateParm;
Douglas Gregor4afa39d2009-01-20 01:17:11 +00001115}
1116
John McCall80cd64a2010-01-29 01:45:37 +00001117
1118// Specialization selected when ToTy is not a known subclass of DeclContext.
1119template <class ToTy,
1120 bool IsKnownSubtype = ::llvm::is_base_of< DeclContext, ToTy>::value>
1121struct cast_convert_decl_context {
1122 static const ToTy *doit(const DeclContext *Val) {
1123 return static_cast<const ToTy*>(Decl::castFromDeclContext(Val));
1124 }
1125
1126 static ToTy *doit(DeclContext *Val) {
1127 return static_cast<ToTy*>(Decl::castFromDeclContext(Val));
1128 }
1129};
1130
1131// Specialization selected when ToTy is a known subclass of DeclContext.
1132template <class ToTy>
1133struct cast_convert_decl_context<ToTy, true> {
1134 static const ToTy *doit(const DeclContext *Val) {
1135 return static_cast<const ToTy*>(Val);
1136 }
1137
1138 static ToTy *doit(DeclContext *Val) {
1139 return static_cast<ToTy*>(Val);
1140 }
1141};
1142
1143
Chris Lattner0ed844b2008-04-04 06:12:32 +00001144} // end clang.
1145
1146namespace llvm {
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +00001147
John McCall80cd64a2010-01-29 01:45:37 +00001148/// isa<T>(DeclContext*)
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +00001149template<class ToTy>
1150struct isa_impl_wrap<ToTy,
1151 const ::clang::DeclContext,const ::clang::DeclContext> {
1152 static bool doit(const ::clang::DeclContext &Val) {
John McCall80cd64a2010-01-29 01:45:37 +00001153 return ToTy::classofKind(Val.getDeclKind());
Chris Lattner0ed844b2008-04-04 06:12:32 +00001154 }
1155};
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +00001156template<class ToTy>
1157struct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext>
1158 : public isa_impl_wrap<ToTy,
1159 const ::clang::DeclContext,const ::clang::DeclContext> {};
Chris Lattner0ed844b2008-04-04 06:12:32 +00001160
John McCall80cd64a2010-01-29 01:45:37 +00001161/// cast<T>(DeclContext*)
1162template<class ToTy>
1163struct cast_convert_val<ToTy,
1164 const ::clang::DeclContext,const ::clang::DeclContext> {
1165 static const ToTy &doit(const ::clang::DeclContext &Val) {
1166 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
1167 }
1168};
1169template<class ToTy>
1170struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> {
1171 static ToTy &doit(::clang::DeclContext &Val) {
1172 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
1173 }
1174};
1175template<class ToTy>
1176struct cast_convert_val<ToTy,
1177 const ::clang::DeclContext*, const ::clang::DeclContext*> {
1178 static const ToTy *doit(const ::clang::DeclContext *Val) {
1179 return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
1180 }
1181};
1182template<class ToTy>
1183struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> {
1184 static ToTy *doit(::clang::DeclContext *Val) {
1185 return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
1186 }
1187};
1188
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +00001189/// Implement cast_convert_val for Decl -> DeclContext conversions.
Chris Lattner0ed844b2008-04-04 06:12:32 +00001190template<class FromTy>
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +00001191struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> {
Chris Lattnerb048c982008-04-06 04:47:34 +00001192 static ::clang::DeclContext &doit(const FromTy &Val) {
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +00001193 return *FromTy::castToDeclContext(&Val);
Chris Lattner0ed844b2008-04-04 06:12:32 +00001194 }
1195};
Chris Lattner0ed844b2008-04-04 06:12:32 +00001196
1197template<class FromTy>
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +00001198struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> {
Chris Lattnerb048c982008-04-06 04:47:34 +00001199 static ::clang::DeclContext *doit(const FromTy *Val) {
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +00001200 return FromTy::castToDeclContext(Val);
Chris Lattner0ed844b2008-04-04 06:12:32 +00001201 }
1202};
Argyrios Kyrtzidis42220c52008-10-12 16:14:48 +00001203
Douglas Gregor44b43212008-12-11 16:49:14 +00001204template<class FromTy>
1205struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> {
1206 static const ::clang::DeclContext &doit(const FromTy &Val) {
1207 return *FromTy::castToDeclContext(&Val);
1208 }
1209};
1210
1211template<class FromTy>
1212struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> {
1213 static const ::clang::DeclContext *doit(const FromTy *Val) {
1214 return FromTy::castToDeclContext(Val);
1215 }
1216};
1217
Chris Lattner0ed844b2008-04-04 06:12:32 +00001218} // end namespace llvm
1219
1220#endif