blob: b165991c172c3cb9b8bdaf5cdf6c84ae80d805bc [file] [log] [blame]
Chris Lattner0ed844b2008-04-04 06:12:32 +00001//===-- DeclBase.h - Base Classes for representing declarations *- C++ -*-===//
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 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"
19#include "clang/Basic/SourceLocation.h"
20
21namespace clang {
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000022class TranslationUnitDecl;
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000023class NamespaceDecl;
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000024class ScopedDecl;
Chris Lattner0ed844b2008-04-04 06:12:32 +000025class FunctionDecl;
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000026class CXXRecordDecl;
Chris Lattnerb048c982008-04-06 04:47:34 +000027class EnumDecl;
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000028class ObjCMethodDecl;
Chris Lattner0ed844b2008-04-04 06:12:32 +000029class ObjCInterfaceDecl;
Steve Naroff56ee6892008-10-08 17:01:13 +000030class BlockDecl;
Chris Lattner0ed844b2008-04-04 06:12:32 +000031
32/// Decl - This represents one declaration (or definition), e.g. a variable,
33/// typedef, function, struct, etc.
34///
35class Decl {
36public:
37 enum Kind {
38 // This lists the concrete classes of Decl in order of the inheritance
39 // hierarchy. This allows us to do efficient classof tests based on the
40 // enums below. The commented out names are abstract class names.
Ted Kremeneka34ea072008-08-04 22:51:42 +000041 // [DeclContext] indicates that the class also inherits from DeclContext.
Chris Lattner0ed844b2008-04-04 06:12:32 +000042
43 // Decl
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000044 TranslationUnit, // [DeclContext]
Chris Lattner0ed844b2008-04-04 06:12:32 +000045 // NamedDecl
46 Field,
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000047 CXXField,
Chris Lattner0ed844b2008-04-04 06:12:32 +000048 ObjCIvar,
Ted Kremenek01e67792008-08-20 03:26:33 +000049 ObjCAtDefsField,
Chris Lattner0ed844b2008-04-04 06:12:32 +000050 ObjCCategory,
51 ObjCCategoryImpl,
52 ObjCImplementation,
53 ObjCProtocol,
Sam Bishop670aa9d2008-04-08 20:49:25 +000054 ObjCProperty,
Chris Lattner0ed844b2008-04-04 06:12:32 +000055 // ScopedDecl
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000056 Namespace, // [DeclContext]
Chris Lattner0ed844b2008-04-04 06:12:32 +000057 // TypeDecl
58 Typedef,
59 // TagDecl
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000060 Enum, // [DeclContext]
Chris Lattner0ed844b2008-04-04 06:12:32 +000061 // RecordDecl
62 Struct,
63 Union,
64 Class,
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000065 // CXXRecordDecl [DeclContext]
66 CXXStruct,
67 CXXUnion,
68 CXXClass,
Chris Lattner0ed844b2008-04-04 06:12:32 +000069 // ValueDecl
70 EnumConstant,
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000071 Function, // [DeclContext]
72 CXXMethod,
Steve Naroff248a7532008-04-15 22:42:06 +000073 Var,
Chris Lattner41110242008-06-17 18:05:57 +000074 ImplicitParam,
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000075 CXXClassVar,
Chris Lattner0ed844b2008-04-04 06:12:32 +000076 ParmVar,
Daniel Dunbar226e04a2008-08-15 23:18:35 +000077 ObjCInterface, // [DeclContext]
78 ObjCCompatibleAlias,
79 ObjCMethod, // [DeclContext]
80 ObjCClass,
81 ObjCForwardProtocol,
82 ObjCPropertyImpl,
Chris Lattner0ed844b2008-04-04 06:12:32 +000083 LinkageSpec,
Daniel Dunbar226e04a2008-08-15 23:18:35 +000084 FileScopeAsm,
Steve Naroff56ee6892008-10-08 17:01:13 +000085 Block, // [DeclContext]
Chris Lattner0ed844b2008-04-04 06:12:32 +000086
87 // For each non-leaf class, we now define a mapping to the first/last member
88 // of the class, to allow efficient classof.
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000089 NamedFirst = Field , NamedLast = ParmVar,
Ted Kremenek01e67792008-08-20 03:26:33 +000090 FieldFirst = Field , FieldLast = ObjCAtDefsField,
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +000091 ScopedFirst = Namespace , ScopedLast = ParmVar,
92 TypeFirst = Typedef , TypeLast = CXXClass,
93 TagFirst = Enum , TagLast = CXXClass,
94 RecordFirst = Struct , RecordLast = CXXClass,
95 CXXRecordFirst = CXXStruct , CXXRecordLast = CXXClass,
96 ValueFirst = EnumConstant , ValueLast = ParmVar,
97 FunctionFirst = Function , FunctionLast = CXXMethod,
98 VarFirst = Var , VarLast = ParmVar
Chris Lattner0ed844b2008-04-04 06:12:32 +000099 };
100
101 /// IdentifierNamespace - According to C99 6.2.3, there are four namespaces,
Douglas Gregor2ce52f32008-04-13 21:07:44 +0000102 /// labels, tags, members and ordinary identifiers. These are meant
103 /// as bitmasks, so that searches in C++ can look into the "tag" namespace
104 /// during ordinary lookup.
Chris Lattner0ed844b2008-04-04 06:12:32 +0000105 enum IdentifierNamespace {
Douglas Gregor2ce52f32008-04-13 21:07:44 +0000106 IDNS_Label = 0x1,
107 IDNS_Tag = 0x2,
108 IDNS_Member = 0x4,
109 IDNS_Ordinary = 0x8
Chris Lattner0ed844b2008-04-04 06:12:32 +0000110 };
111
112 /// ObjCDeclQualifier - Qualifier used on types in method declarations
113 /// for remote messaging. They are meant for the arguments though and
114 /// applied to the Decls (ObjCMethodDecl and ParmVarDecl).
115 enum ObjCDeclQualifier {
116 OBJC_TQ_None = 0x0,
117 OBJC_TQ_In = 0x1,
118 OBJC_TQ_Inout = 0x2,
119 OBJC_TQ_Out = 0x4,
120 OBJC_TQ_Bycopy = 0x8,
121 OBJC_TQ_Byref = 0x10,
122 OBJC_TQ_Oneway = 0x20
123 };
124
125private:
126 /// Loc - The location that this decl.
127 SourceLocation Loc;
128
129 /// DeclKind - This indicates which class this is.
130 Kind DeclKind : 8;
131
132 /// InvalidDecl - This indicates a semantic error occurred.
133 unsigned int InvalidDecl : 1;
134
135 /// HasAttrs - This indicates whether the decl has attributes or not.
136 unsigned int HasAttrs : 1;
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000137
138 protected:
139 /// Access - Used by C++ decls for the access specifier.
140 // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
141 unsigned Access : 2;
142 friend class CXXClassMemberWrapper;
143
Chris Lattner0ed844b2008-04-04 06:12:32 +0000144 Decl(Kind DK, SourceLocation L) : Loc(L), DeclKind(DK), InvalidDecl(0),
145 HasAttrs(false) {
146 if (Decl::CollectingStats()) addDeclKind(DK);
147 }
Sam Bishop1bb19632008-04-11 18:04:39 +0000148
Chris Lattner0ed844b2008-04-04 06:12:32 +0000149 virtual ~Decl();
Sam Bishop1bb19632008-04-11 18:04:39 +0000150
151public:
Chris Lattner0ed844b2008-04-04 06:12:32 +0000152 SourceLocation getLocation() const { return Loc; }
153 void setLocation(SourceLocation L) { Loc = L; }
154
155 Kind getKind() const { return DeclKind; }
156 const char *getDeclKindName() const;
157
158 void addAttr(Attr *attr);
159 const Attr *getAttrs() const;
Chris Lattnera212c562008-05-04 02:29:49 +0000160 void swapAttrs(Decl *D);
Nuno Lopes9141bee2008-06-01 22:53:53 +0000161 void invalidateAttrs();
Chris Lattner0ed844b2008-04-04 06:12:32 +0000162
163 template<typename T> const T *getAttr() const {
164 for (const Attr *attr = getAttrs(); attr; attr = attr->getNext())
165 if (const T *V = dyn_cast<T>(attr))
166 return V;
167
168 return 0;
169 }
170
171 /// setInvalidDecl - Indicates the Decl had a semantic error. This
172 /// allows for graceful error recovery.
173 void setInvalidDecl() { InvalidDecl = 1; }
174 bool isInvalidDecl() const { return (bool) InvalidDecl; }
175
176 IdentifierNamespace getIdentifierNamespace() const {
177 switch (DeclKind) {
178 default: assert(0 && "Unknown decl kind!");
Chris Lattner41110242008-06-17 18:05:57 +0000179 case ImplicitParam:
Chris Lattner0ed844b2008-04-04 06:12:32 +0000180 case Typedef:
181 case Function:
Steve Naroff248a7532008-04-15 22:42:06 +0000182 case Var:
Chris Lattner0ed844b2008-04-04 06:12:32 +0000183 case ParmVar:
184 case EnumConstant:
185 case ObjCInterface:
186 case ObjCCompatibleAlias:
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000187 case CXXField:
Argyrios Kyrtzidis1ce6ead2008-06-24 22:56:42 +0000188 case CXXMethod:
Argyrios Kyrtzidis09c31b02008-06-25 14:04:17 +0000189 case CXXClassVar:
Chris Lattner0ed844b2008-04-04 06:12:32 +0000190 return IDNS_Ordinary;
191 case Struct:
192 case Union:
193 case Class:
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000194 case CXXStruct:
195 case CXXUnion:
196 case CXXClass:
Chris Lattner0ed844b2008-04-04 06:12:32 +0000197 case Enum:
198 return IDNS_Tag;
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000199 case Namespace:
200 return IdentifierNamespace(IDNS_Tag | IDNS_Ordinary);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000201 }
202 }
Ted Kremenek792481e2008-06-20 21:39:47 +0000203
Ted Kremenek69c8f0a2008-07-31 17:32:12 +0000204 // getBody - If this Decl represents a declaration for a body of code,
Ted Kremenek792481e2008-06-20 21:39:47 +0000205 // such as a function or method definition, this method returns the top-level
Ted Kremenek69c8f0a2008-07-31 17:32:12 +0000206 // Stmt* of that body. Otherwise this method returns null.
207 virtual Stmt* getBody() const { return 0; }
Ted Kremenek792481e2008-06-20 21:39:47 +0000208
Chris Lattner0ed844b2008-04-04 06:12:32 +0000209 // global temp stats (until we have a per-module visitor)
210 static void addDeclKind(Kind k);
211 static bool CollectingStats(bool Enable = false);
212 static void PrintStats();
213
214 // Implement isa/cast/dyncast/etc.
215 static bool classof(const Decl *) { return true; }
216
217 /// Emit - Serialize this Decl to Bitcode.
218 void Emit(llvm::Serializer& S) const;
219
220 /// Create - Deserialize a Decl from Bitcode.
Sam Bishope2563ca2008-04-07 21:55:54 +0000221 static Decl* Create(llvm::Deserializer& D, ASTContext& C);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000222
Sam Bishopbb45c512008-04-11 15:01:25 +0000223 /// Destroy - Call destructors and release memory.
Ted Kremenek27f8a282008-05-20 00:43:19 +0000224 virtual void Destroy(ASTContext& C);
Sam Bishopbb45c512008-04-11 15:01:25 +0000225
Chris Lattner0ed844b2008-04-04 06:12:32 +0000226protected:
227 /// EmitImpl - Provides the subclass-specific serialization logic for
228 /// serializing out a decl.
229 virtual void EmitImpl(llvm::Serializer& S) const {
230 // FIXME: This will eventually be a pure virtual function.
231 assert (false && "Not implemented.");
232 }
233
234 void EmitInRec(llvm::Serializer& S) const;
Sam Bishope2563ca2008-04-07 21:55:54 +0000235 void ReadInRec(llvm::Deserializer& D, ASTContext& C);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000236};
237
Chris Lattnerb048c982008-04-06 04:47:34 +0000238/// DeclContext - This is used only as base class of specific decl types that
Chris Lattner0ed844b2008-04-04 06:12:32 +0000239/// can act as declaration contexts. These decls are:
240///
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000241/// TranslationUnitDecl
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000242/// NamespaceDecl
Chris Lattner0ed844b2008-04-04 06:12:32 +0000243/// FunctionDecl
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000244/// CXXRecordDecl
Chris Lattnerb048c982008-04-06 04:47:34 +0000245/// EnumDecl
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000246/// ObjCMethodDecl
Chris Lattner0ed844b2008-04-04 06:12:32 +0000247/// ObjCInterfaceDecl
Steve Naroff56ee6892008-10-08 17:01:13 +0000248/// BlockDecl
Chris Lattner0ed844b2008-04-04 06:12:32 +0000249///
Chris Lattnerb048c982008-04-06 04:47:34 +0000250class DeclContext {
Chris Lattner0ed844b2008-04-04 06:12:32 +0000251 /// DeclKind - This indicates which class this is.
252 Decl::Kind DeclKind : 8;
253
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000254 /// DeclChain - Linked list of declarations that are defined inside this
255 /// declaration context.
256 ScopedDecl *DeclChain;
257
Chris Lattner0ed844b2008-04-04 06:12:32 +0000258 // Used in the CastTo template to get the DeclKind
Chris Lattnerb048c982008-04-06 04:47:34 +0000259 // from a Decl or a DeclContext. DeclContext doesn't have a getKind() method
Chris Lattner0ed844b2008-04-04 06:12:32 +0000260 // to avoid 'ambiguous access' compiler errors.
261 template<typename T> struct KindTrait {
262 static Decl::Kind getKind(const T *D) { return D->getKind(); }
263 };
264
265 // Used only by the ToDecl and FromDecl methods
266 template<typename To, typename From>
267 static To *CastTo(const From *D) {
268 Decl::Kind DK = KindTrait<From>::getKind(D);
269 switch(DK) {
Steve Naroff090276f2008-10-10 01:28:17 +0000270 case Decl::Block:
271 return static_cast<BlockDecl*>(const_cast<From*>(D));
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000272 case Decl::TranslationUnit:
273 return static_cast<TranslationUnitDecl*>(const_cast<From*>(D));
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000274 case Decl::Namespace:
275 return static_cast<NamespaceDecl*>(const_cast<From*>(D));
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000276 case Decl::Enum:
277 return static_cast<EnumDecl*>(const_cast<From*>(D));
Chris Lattner0ed844b2008-04-04 06:12:32 +0000278 case Decl::ObjCMethod:
279 return static_cast<ObjCMethodDecl*>(const_cast<From*>(D));
280 case Decl::ObjCInterface:
281 return static_cast<ObjCInterfaceDecl*>(const_cast<From*>(D));
282 default:
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000283 if (DK >= Decl::FunctionFirst && DK <= Decl::FunctionLast)
284 return static_cast<FunctionDecl*>(const_cast<From*>(D));
285 if (DK >= Decl::CXXRecordFirst && DK <= Decl::CXXRecordLast)
286 return static_cast<CXXRecordDecl*>(const_cast<From*>(D));
287
Chris Lattnerb048c982008-04-06 04:47:34 +0000288 assert(false && "a decl that inherits DeclContext isn't handled");
Chris Lattner0ed844b2008-04-04 06:12:32 +0000289 return 0;
290 }
291 }
292
293protected:
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000294 DeclContext(Decl::Kind K) : DeclKind(K), DeclChain(0) {}
Chris Lattner0ed844b2008-04-04 06:12:32 +0000295
296public:
Chris Lattnerb048c982008-04-06 04:47:34 +0000297 /// getParent - Returns the containing DeclContext if this is a ScopedDecl,
Chris Lattner0ed844b2008-04-04 06:12:32 +0000298 /// else returns NULL.
Chris Lattnerb048c982008-04-06 04:47:34 +0000299 DeclContext *getParent() const;
Chris Lattner0ed844b2008-04-04 06:12:32 +0000300
301 bool isFunctionOrMethod() const {
302 switch (DeclKind) {
Steve Naroff56ee6892008-10-08 17:01:13 +0000303 case Decl::Block:
Chris Lattner0ed844b2008-04-04 06:12:32 +0000304 case Decl::Function:
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000305 case Decl::CXXMethod:
Chris Lattner0ed844b2008-04-04 06:12:32 +0000306 case Decl::ObjCMethod:
307 return true;
308 default:
309 return false;
310 }
311 }
312
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000313 ScopedDecl *getDeclChain() const { return DeclChain; }
314 void setDeclChain(ScopedDecl *D) { DeclChain = D; }
315
Chris Lattnerb048c982008-04-06 04:47:34 +0000316 /// ToDecl and FromDecl make Decl <-> DeclContext castings.
Chris Lattner0ed844b2008-04-04 06:12:32 +0000317 /// They are intended to be used by the simplify_type and cast_convert_val
318 /// templates.
Chris Lattnerb048c982008-04-06 04:47:34 +0000319 static Decl *ToDecl (const DeclContext *D);
320 static DeclContext *FromDecl (const Decl *D);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000321
322 static bool classof(const Decl *D) {
323 switch (D->getKind()) {
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000324 case Decl::TranslationUnit:
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000325 case Decl::Namespace:
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000326 case Decl::Enum:
Chris Lattner0ed844b2008-04-04 06:12:32 +0000327 case Decl::ObjCMethod:
328 case Decl::ObjCInterface:
Steve Naroff56ee6892008-10-08 17:01:13 +0000329 case Decl::Block:
Chris Lattner0ed844b2008-04-04 06:12:32 +0000330 return true;
331 default:
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000332 if (D->getKind() >= Decl::FunctionFirst &&
333 D->getKind() <= Decl::FunctionLast)
334 return true;
335 if (D->getKind() >= Decl::CXXRecordFirst &&
336 D->getKind() <= Decl::CXXRecordLast)
337 return true;
Chris Lattnerb048c982008-04-06 04:47:34 +0000338 return false;
Chris Lattner0ed844b2008-04-04 06:12:32 +0000339 }
340 }
Chris Lattnerb048c982008-04-06 04:47:34 +0000341 static bool classof(const DeclContext *D) { return true; }
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +0000342 static bool classof(const TranslationUnitDecl *D) { return true; }
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000343 static bool classof(const NamespaceDecl *D) { return true; }
Chris Lattner0ed844b2008-04-04 06:12:32 +0000344 static bool classof(const FunctionDecl *D) { return true; }
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000345 static bool classof(const CXXRecordDecl *D) { return true; }
Chris Lattnerb048c982008-04-06 04:47:34 +0000346 static bool classof(const EnumDecl *D) { return true; }
Argyrios Kyrtzidisd3bb44f2008-06-09 21:05:31 +0000347 static bool classof(const ObjCMethodDecl *D) { return true; }
Chris Lattner0ed844b2008-04-04 06:12:32 +0000348 static bool classof(const ObjCInterfaceDecl *D) { return true; }
Steve Naroff56ee6892008-10-08 17:01:13 +0000349 static bool classof(const BlockDecl *D) { return true; }
Argyrios Kyrtzidis76435362008-06-10 01:32:09 +0000350
351private:
352 void EmitOutRec(llvm::Serializer& S) const;
353 void ReadOutRec(llvm::Deserializer& D, ASTContext& C);
354
355 friend class Decl;
Chris Lattner0ed844b2008-04-04 06:12:32 +0000356};
357
Chris Lattnerb048c982008-04-06 04:47:34 +0000358template<> struct DeclContext::KindTrait<DeclContext> {
359 static Decl::Kind getKind(const DeclContext *D) { return D->DeclKind; }
Chris Lattner0ed844b2008-04-04 06:12:32 +0000360};
361
362} // end clang.
363
364namespace llvm {
Chris Lattnerb048c982008-04-06 04:47:34 +0000365/// Implement simplify_type for DeclContext, so that we can dyn_cast from
366/// DeclContext to a specific Decl class.
367 template<> struct simplify_type<const ::clang::DeclContext*> {
Chris Lattner0ed844b2008-04-04 06:12:32 +0000368 typedef ::clang::Decl* SimpleType;
Chris Lattnerb048c982008-04-06 04:47:34 +0000369 static SimpleType getSimplifiedValue(const ::clang::DeclContext *Val) {
370 return ::clang::DeclContext::ToDecl(Val);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000371 }
372};
Chris Lattnerb048c982008-04-06 04:47:34 +0000373template<> struct simplify_type< ::clang::DeclContext*>
374 : public simplify_type<const ::clang::DeclContext*> {};
Chris Lattner0ed844b2008-04-04 06:12:32 +0000375
Chris Lattnerb048c982008-04-06 04:47:34 +0000376template<> struct simplify_type<const ::clang::DeclContext> {
Chris Lattner0ed844b2008-04-04 06:12:32 +0000377 typedef ::clang::Decl SimpleType;
Chris Lattnerb048c982008-04-06 04:47:34 +0000378 static SimpleType &getSimplifiedValue(const ::clang::DeclContext &Val) {
379 return *::clang::DeclContext::ToDecl(&Val);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000380 }
381};
Chris Lattnerb048c982008-04-06 04:47:34 +0000382template<> struct simplify_type< ::clang::DeclContext>
383 : public simplify_type<const ::clang::DeclContext> {};
Chris Lattner0ed844b2008-04-04 06:12:32 +0000384
Chris Lattnerb048c982008-04-06 04:47:34 +0000385/// Implement cast_convert_val for DeclContext, so that we can dyn_cast from
386/// a Decl class to DeclContext.
Chris Lattner0ed844b2008-04-04 06:12:32 +0000387template<class FromTy>
Chris Lattnerb048c982008-04-06 04:47:34 +0000388struct cast_convert_val< ::clang::DeclContext,const FromTy,const FromTy> {
389 static ::clang::DeclContext &doit(const FromTy &Val) {
390 return *::clang::DeclContext::FromDecl(&Val);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000391 }
392};
393template<class FromTy>
Chris Lattnerb048c982008-04-06 04:47:34 +0000394struct cast_convert_val< ::clang::DeclContext,FromTy,FromTy>
395 : public cast_convert_val< ::clang::DeclContext,const FromTy,const FromTy>
Chris Lattner0ed844b2008-04-04 06:12:32 +0000396 {};
397
398template<class FromTy>
Chris Lattnerb048c982008-04-06 04:47:34 +0000399struct cast_convert_val< ::clang::DeclContext,const FromTy*,const FromTy*> {
400 static ::clang::DeclContext *doit(const FromTy *Val) {
401 return ::clang::DeclContext::FromDecl(Val);
Chris Lattner0ed844b2008-04-04 06:12:32 +0000402 }
403};
404template<class FromTy>
Chris Lattnerb048c982008-04-06 04:47:34 +0000405struct cast_convert_val< ::clang::DeclContext,FromTy*,FromTy*>
406 : public cast_convert_val< ::clang::DeclContext,const FromTy*,const FromTy*>
Chris Lattner0ed844b2008-04-04 06:12:32 +0000407 {};
408
409} // end namespace llvm
410
411#endif