DeclBase.h revision 40449fe96e2c6210ecb59515aaf939516fc09c22
1//===-- 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// 10// This file defines the Decl and DeclContext interfaces. 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" 19#include "clang/Basic/SourceLocation.h" 20#include "llvm/ADT/PointerIntPair.h" 21#include <vector> 22 23namespace clang { 24class DeclContext; 25class TranslationUnitDecl; 26class NamespaceDecl; 27class NamedDecl; 28class ScopedDecl; 29class FunctionDecl; 30class CXXRecordDecl; 31class EnumDecl; 32class ObjCMethodDecl; 33class ObjCInterfaceDecl; 34class ObjCCategoryDecl; 35class ObjCProtocolDecl; 36class ObjCImplementationDecl; 37class ObjCCategoryImplDecl; 38class LinkageSpecDecl; 39class BlockDecl; 40class DeclarationName; 41 42/// Decl - This represents one declaration (or definition), e.g. a variable, 43/// typedef, function, struct, etc. 44/// 45class Decl { 46public: 47 enum Kind { 48 // This lists the concrete classes of Decl in order of the inheritance 49 // hierarchy. This allows us to do efficient classof tests based on the 50 // enums below. The commented out names are abstract class names. 51 // [DeclContext] indicates that the class also inherits from DeclContext. 52 53 // Decl 54 TranslationUnit, // [DeclContext] 55 // NamedDecl 56 // ObjCContainerDecl // [DeclContext] 57 ObjCCategory, 58 ObjCProtocol, 59 ObjCInterface, 60 OverloadedFunction, 61 ObjCCategoryImpl, // [DeclContext] 62 ObjCImplementation, // [DeclContext] 63 ObjCProperty, 64 // ScopedDecl 65 Field, 66 ObjCIvar, 67 ObjCAtDefsField, 68 Namespace, // [DeclContext] 69 // TypeDecl 70 Typedef, 71 // TagDecl 72 Enum, // [DeclContext] 73 Record, // [DeclContext] 74 CXXRecord, 75 TemplateTypeParm, 76 // ValueDecl 77 EnumConstant, 78 Function, // [DeclContext] 79 CXXMethod, 80 CXXConstructor, 81 CXXDestructor, 82 CXXConversion, 83 Var, 84 ImplicitParam, 85 CXXClassVar, 86 ParmVar, 87 OriginalParmVar, 88 NonTypeTemplateParm, 89 LinkageSpec, // [DeclContext] 90 ObjCMethod, // [DeclContext] 91 ObjCCompatibleAlias, 92 ObjCClass, 93 ObjCForwardProtocol, 94 ObjCPropertyImpl, 95 FileScopeAsm, 96 Block, // [DeclContext] 97 98 // For each non-leaf class, we now define a mapping to the first/last member 99 // of the class, to allow efficient classof. 100 NamedFirst = OverloadedFunction , NamedLast = NonTypeTemplateParm, 101 FieldFirst = Field , FieldLast = ObjCAtDefsField, 102 ScopedFirst = Field , ScopedLast = ObjCMethod, 103 TypeFirst = Typedef , TypeLast = TemplateTypeParm, 104 TagFirst = Enum , TagLast = CXXRecord, 105 RecordFirst = Record , RecordLast = CXXRecord, 106 ValueFirst = EnumConstant , ValueLast = NonTypeTemplateParm, 107 FunctionFirst = Function , FunctionLast = CXXConversion, 108 VarFirst = Var , VarLast = NonTypeTemplateParm 109 }; 110 111 /// IdentifierNamespace - According to C99 6.2.3, there are four namespaces, 112 /// labels, tags, members and ordinary identifiers. These are meant 113 /// as bitmasks, so that searches in C++ can look into the "tag" namespace 114 /// during ordinary lookup. 115 enum IdentifierNamespace { 116 IDNS_Label = 0x1, 117 IDNS_Tag = 0x2, 118 IDNS_Member = 0x4, 119 IDNS_Ordinary = 0x8 120 }; 121 122 /// ObjCDeclQualifier - Qualifier used on types in method declarations 123 /// for remote messaging. They are meant for the arguments though and 124 /// applied to the Decls (ObjCMethodDecl and ParmVarDecl). 125 enum ObjCDeclQualifier { 126 OBJC_TQ_None = 0x0, 127 OBJC_TQ_In = 0x1, 128 OBJC_TQ_Inout = 0x2, 129 OBJC_TQ_Out = 0x4, 130 OBJC_TQ_Bycopy = 0x8, 131 OBJC_TQ_Byref = 0x10, 132 OBJC_TQ_Oneway = 0x20 133 }; 134 135private: 136 /// Loc - The location that this decl. 137 SourceLocation Loc; 138 139 /// DeclKind - This indicates which class this is. 140 Kind DeclKind : 8; 141 142 /// InvalidDecl - This indicates a semantic error occurred. 143 unsigned int InvalidDecl : 1; 144 145 /// HasAttrs - This indicates whether the decl has attributes or not. 146 unsigned int HasAttrs : 1; 147 148 /// Implicit - Whether this declaration was implicitly generated by 149 /// the implementation rather than explicitly written by the user. 150 bool Implicit : 1; 151 152 protected: 153 /// Access - Used by C++ decls for the access specifier. 154 // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum 155 unsigned Access : 2; 156 friend class CXXClassMemberWrapper; 157 158 Decl(Kind DK, SourceLocation L) : Loc(L), DeclKind(DK), InvalidDecl(0), 159 HasAttrs(false), Implicit(false) { 160 if (Decl::CollectingStats()) addDeclKind(DK); 161 } 162 163 virtual ~Decl(); 164 165public: 166 SourceLocation getLocation() const { return Loc; } 167 void setLocation(SourceLocation L) { Loc = L; } 168 169 Kind getKind() const { return DeclKind; } 170 const char *getDeclKindName() const; 171 172 void addAttr(Attr *attr); 173 const Attr *getAttrs() const; 174 void swapAttrs(Decl *D); 175 void invalidateAttrs(); 176 177 template<typename T> const T *getAttr() const { 178 for (const Attr *attr = getAttrs(); attr; attr = attr->getNext()) 179 if (const T *V = dyn_cast<T>(attr)) 180 return V; 181 182 return 0; 183 } 184 185 /// setInvalidDecl - Indicates the Decl had a semantic error. This 186 /// allows for graceful error recovery. 187 void setInvalidDecl() { InvalidDecl = 1; } 188 bool isInvalidDecl() const { return (bool) InvalidDecl; } 189 190 /// isImplicit - Indicates whether the declaration was implicitly 191 /// generated by the implementation. If false, this declaration 192 /// was written explicitly in the source code. 193 bool isImplicit() const { return Implicit; } 194 void setImplicit(bool I = true) { Implicit = I; } 195 196 IdentifierNamespace getIdentifierNamespace() const { 197 switch (DeclKind) { 198 default: 199 if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast) 200 return IDNS_Ordinary; 201 assert(0 && "Unknown decl kind!"); 202 case ImplicitParam: 203 case Typedef: 204 case Var: 205 case ParmVar: 206 case OriginalParmVar: 207 case EnumConstant: 208 case NonTypeTemplateParm: 209 case Field: 210 case ObjCAtDefsField: 211 case ObjCIvar: 212 case ObjCInterface: 213 case ObjCCompatibleAlias: 214 case OverloadedFunction: 215 case CXXMethod: 216 case CXXConversion: 217 case CXXClassVar: 218 return IDNS_Ordinary; 219 case Record: 220 case CXXRecord: 221 case TemplateTypeParm: 222 case Enum: 223 return IDNS_Tag; 224 case Namespace: 225 return IdentifierNamespace(IDNS_Tag | IDNS_Ordinary); 226 } 227 } 228 229 bool isInIdentifierNamespace(unsigned NS) const { 230 return getIdentifierNamespace() & NS; 231 } 232 233 // getBody - If this Decl represents a declaration for a body of code, 234 // such as a function or method definition, this method returns the top-level 235 // Stmt* of that body. Otherwise this method returns null. 236 virtual Stmt* getBody() const { return 0; } 237 238 // global temp stats (until we have a per-module visitor) 239 static void addDeclKind(Kind k); 240 static bool CollectingStats(bool Enable = false); 241 static void PrintStats(); 242 243 /// isTemplateParameter - Determines whether this declartion is a 244 /// template parameter. 245 bool isTemplateParameter() const; 246 247 // Implement isa/cast/dyncast/etc. 248 static bool classof(const Decl *) { return true; } 249 static DeclContext *castToDeclContext(const Decl *); 250 static Decl *castFromDeclContext(const DeclContext *); 251 252 /// Emit - Serialize this Decl to Bitcode. 253 void Emit(llvm::Serializer& S) const; 254 255 /// Create - Deserialize a Decl from Bitcode. 256 static Decl* Create(llvm::Deserializer& D, ASTContext& C); 257 258 /// Destroy - Call destructors and release memory. 259 virtual void Destroy(ASTContext& C); 260 261protected: 262 /// EmitImpl - Provides the subclass-specific serialization logic for 263 /// serializing out a decl. 264 virtual void EmitImpl(llvm::Serializer& S) const { 265 // FIXME: This will eventually be a pure virtual function. 266 assert (false && "Not implemented."); 267 } 268 269 void EmitInRec(llvm::Serializer& S) const; 270 void ReadInRec(llvm::Deserializer& D, ASTContext& C); 271}; 272 273/// DeclContext - This is used only as base class of specific decl types that 274/// can act as declaration contexts. These decls are: 275/// 276/// TranslationUnitDecl 277/// NamespaceDecl 278/// FunctionDecl 279/// RecordDecl/CXXRecordDecl 280/// EnumDecl 281/// ObjCMethodDecl 282/// ObjCInterfaceDecl 283/// LinkageSpecDecl 284/// BlockDecl 285class DeclContext { 286 /// DeclKind - This indicates which class this is. 287 Decl::Kind DeclKind : 8; 288 289 /// LookupPtrKind - Describes what kind of pointer LookupPtr 290 /// actually is. 291 enum LookupPtrKind { 292 /// LookupIsMap - Indicates that LookupPtr is actually a map. 293 LookupIsMap = 7 294 }; 295 296 /// LookupPtr - Pointer to a data structure used to lookup 297 /// declarations within this context. If the context contains fewer 298 /// than seven declarations, the number of declarations is provided 299 /// in the 3 lowest-order bits and the upper bits are treated as a 300 /// pointer to an array of ScopedDecl pointers. If the context 301 /// contains seven or more declarations, the upper bits are treated 302 /// as a pointer to a DenseMap<DeclarationName, std::vector<ScopedDecl>>. 303 /// FIXME: We need a better data structure for this. 304 llvm::PointerIntPair<void*, 3> LookupPtr; 305 306 /// Decls - Contains all of the declarations that are defined inside 307 /// this declaration context. 308 std::vector<ScopedDecl*> Decls; 309 310 // Used in the CastTo template to get the DeclKind 311 // from a Decl or a DeclContext. DeclContext doesn't have a getKind() method 312 // to avoid 'ambiguous access' compiler errors. 313 template<typename T> struct KindTrait { 314 static Decl::Kind getKind(const T *D) { return D->getKind(); } 315 }; 316 317 // Used only by the ToDecl and FromDecl methods 318 template<typename To, typename From> 319 static To *CastTo(const From *D) { 320 Decl::Kind DK = KindTrait<From>::getKind(D); 321 switch(DK) { 322 case Decl::TranslationUnit: 323 return static_cast<TranslationUnitDecl*>(const_cast<From*>(D)); 324 case Decl::Namespace: 325 return static_cast<NamespaceDecl*>(const_cast<From*>(D)); 326 case Decl::Enum: 327 return static_cast<EnumDecl*>(const_cast<From*>(D)); 328 case Decl::Record: 329 return static_cast<RecordDecl*>(const_cast<From*>(D)); 330 case Decl::CXXRecord: 331 return static_cast<CXXRecordDecl*>(const_cast<From*>(D)); 332 case Decl::ObjCMethod: 333 return static_cast<ObjCMethodDecl*>(const_cast<From*>(D)); 334 case Decl::ObjCInterface: 335 return static_cast<ObjCInterfaceDecl*>(const_cast<From*>(D)); 336 case Decl::ObjCCategory: 337 return static_cast<ObjCCategoryDecl*>(const_cast<From*>(D)); 338 case Decl::ObjCProtocol: 339 return static_cast<ObjCProtocolDecl*>(const_cast<From*>(D)); 340 case Decl::ObjCImplementation: 341 return static_cast<ObjCImplementationDecl*>(const_cast<From*>(D)); 342 case Decl::ObjCCategoryImpl: 343 return static_cast<ObjCCategoryImplDecl*>(const_cast<From*>(D)); 344 case Decl::LinkageSpec: 345 return static_cast<LinkageSpecDecl*>(const_cast<From*>(D)); 346 case Decl::Block: 347 return static_cast<BlockDecl*>(const_cast<From*>(D)); 348 default: 349 if (DK >= Decl::FunctionFirst && DK <= Decl::FunctionLast) 350 return static_cast<FunctionDecl*>(const_cast<From*>(D)); 351 352 assert(false && "a decl that inherits DeclContext isn't handled"); 353 return 0; 354 } 355 } 356 357 /// isLookupMap - Determine if the lookup structure is a 358 /// DenseMap. Othewise, it is an array. 359 bool isLookupMap() const { return LookupPtr.getInt() == LookupIsMap; } 360 361protected: 362 DeclContext(Decl::Kind K) : DeclKind(K), LookupPtr() { 363 } 364 365 void DestroyDecls(ASTContext &C); 366 367public: 368 ~DeclContext(); 369 370 /// getParent - Returns the containing DeclContext if this is a ScopedDecl, 371 /// else returns NULL. 372 const DeclContext *getParent() const; 373 DeclContext *getParent() { 374 return const_cast<DeclContext*>( 375 const_cast<const DeclContext*>(this)->getParent()); 376 } 377 378 /// getLexicalParent - Returns the containing lexical DeclContext. May be 379 /// different from getParent, e.g.: 380 /// 381 /// namespace A { 382 /// struct S; 383 /// } 384 /// struct A::S {}; // getParent() == namespace 'A' 385 /// // getLexicalParent() == translation unit 386 /// 387 const DeclContext *getLexicalParent() const; 388 DeclContext *getLexicalParent() { 389 return const_cast<DeclContext*>( 390 const_cast<const DeclContext*>(this)->getLexicalParent()); 391 } 392 393 bool isFunctionOrMethod() const { 394 switch (DeclKind) { 395 case Decl::Block: 396 case Decl::ObjCMethod: 397 return true; 398 399 default: 400 if (DeclKind >= Decl::FunctionFirst && DeclKind <= Decl::FunctionLast) 401 return true; 402 return false; 403 } 404 } 405 406 bool isFileContext() const { 407 return DeclKind == Decl::TranslationUnit || DeclKind == Decl::Namespace; 408 } 409 410 bool isRecord() const { 411 return DeclKind == Decl::Record || DeclKind == Decl::CXXRecord; 412 } 413 414 bool isNamespace() const { 415 return DeclKind == Decl::Namespace; 416 } 417 418 /// isTransparentContext - Determines whether this context is a 419 /// "transparent" context, meaning that the members declared in this 420 /// context are semantically declared in the nearest enclosing 421 /// non-transparent (opaque) context but are lexically declared in 422 /// this context. For example, consider the enumerators of an 423 /// enumeration type: 424 /// @code 425 /// enum E { 426 /// Val1 427 /// }; 428 /// @endcode 429 /// Here, E is a transparent context, so its enumerator (Val1) will 430 /// appear (semantically) that it is in the same context of E. 431 /// Examples of transparent contexts include: enumerations (except for 432 /// C++0x scoped enums), C++ linkage specifications, and C++0x 433 /// inline namespaces. 434 bool isTransparentContext() const; 435 436 bool Encloses(DeclContext *DC) const { 437 for (; DC; DC = DC->getParent()) 438 if (DC == this) 439 return true; 440 return false; 441 } 442 443 /// getPrimaryContext - There may be many different 444 /// declarations of the same entity (including forward declarations 445 /// of classes, multiple definitions of namespaces, etc.), each with 446 /// a different set of declarations. This routine returns the 447 /// "primary" DeclContext structure, which will contain the 448 /// information needed to perform name lookup into this context. 449 DeclContext *getPrimaryContext(); 450 451 /// getLookupContext - Retrieve the innermost non-transparent 452 /// context of this context, which corresponds to the innermost 453 /// location from which name lookup can find the entities in this 454 /// context. 455 DeclContext *getLookupContext() { 456 return const_cast<DeclContext *>( 457 const_cast<const DeclContext *>(this)->getLookupContext()); 458 } 459 const DeclContext *getLookupContext() const; 460 461 /// getNextContext - If this is a DeclContext that may have other 462 /// DeclContexts that are semantically connected but syntactically 463 /// different, such as C++ namespaces, this routine retrieves the 464 /// next DeclContext in the link. Iteration through the chain of 465 /// DeclContexts should begin at the primary DeclContext and 466 /// continue until this function returns NULL. For example, given: 467 /// @code 468 /// namespace N { 469 /// int x; 470 /// } 471 /// namespace N { 472 /// int y; 473 /// } 474 /// @endcode 475 /// The first occurrence of namespace N will be the primary 476 /// DeclContext. Its getNextContext will return the second 477 /// occurrence of namespace N. 478 DeclContext *getNextContext(); 479 480 /// decl_iterator - Iterates through the declarations stored 481 /// within this context. 482 typedef std::vector<ScopedDecl*>::const_iterator decl_iterator; 483 484 /// decls_begin/decls_end - Iterate over the declarations stored in 485 /// this context. 486 decl_iterator decls_begin() const { return Decls.begin(); } 487 decl_iterator decls_end() const { return Decls.end(); } 488 489 /// addDecl - Add the declaration D to this scope. Note that 490 /// declarations are added at the beginning of the declaration 491 /// chain, so reverseDeclChain() should be called after all 492 /// declarations have been added. If AllowLookup, also adds this 493 /// declaration into data structure for name lookup. 494 void addDecl(ASTContext &Context, ScopedDecl *D, bool AllowLookup = true); 495 496 void buildLookup(DeclContext *DCtx); 497 498 /// lookup_iterator - An iterator that provides access to the results 499 /// of looking up a name within this context. 500 typedef ScopedDecl **lookup_iterator; 501 502 /// lookup_const_iterator - An iterator that provides non-mutable 503 /// access to the results of lookup up a name within this context. 504 typedef ScopedDecl * const * lookup_const_iterator; 505 506 typedef std::pair<lookup_iterator, lookup_iterator> lookup_result; 507 typedef std::pair<lookup_const_iterator, lookup_const_iterator> 508 lookup_const_result; 509 510 /// lookup - Find the declarations (if any) with the given Name in 511 /// this context. Returns a range of iterators that contains all of 512 /// the declarations with this name (which may be 0, 1, or more 513 /// declarations). If two declarations are returned, the declaration 514 /// in the "ordinary" identifier namespace will precede the 515 /// declaration in the "tag" identifier namespace (e.g., values 516 /// before types). Note that this routine will not look into parent 517 /// contexts. 518 lookup_result lookup(DeclarationName Name); 519 lookup_const_result lookup(DeclarationName Name) const; 520 521 /// insert - Insert the declaration D into this context. Up to two 522 /// declarations with the same name can be inserted into a single 523 /// declaration context, one in the "tag" namespace (e.g., for 524 /// classes and enums) and one in the "ordinary" namespaces (e.g., 525 /// for variables, functions, and other values). Note that, if there 526 /// is already a declaration with the same name and identifier 527 /// namespace, D will replace it. It is up to the caller to ensure 528 /// that this replacement is semantically correct, e.g., that 529 /// declarations are only replaced by later declarations of the same 530 /// entity and not a declaration of some other kind of entity. 531 void insert(ASTContext &Context, ScopedDecl *D); 532 533 static bool classof(const Decl *D) { 534 switch (D->getKind()) { 535 case Decl::TranslationUnit: 536 case Decl::Namespace: 537 case Decl::Enum: 538 case Decl::Record: 539 case Decl::CXXRecord: 540 case Decl::ObjCMethod: 541 case Decl::ObjCInterface: 542 case Decl::ObjCCategory: 543 case Decl::ObjCProtocol: 544 case Decl::ObjCImplementation: 545 case Decl::ObjCCategoryImpl: 546 case Decl::LinkageSpec: 547 case Decl::Block: 548 return true; 549 default: 550 if (D->getKind() >= Decl::FunctionFirst && 551 D->getKind() <= Decl::FunctionLast) 552 return true; 553 return false; 554 } 555 } 556 static bool classof(const DeclContext *D) { return true; } 557 static bool classof(const TranslationUnitDecl *D) { return true; } 558 static bool classof(const NamespaceDecl *D) { return true; } 559 static bool classof(const FunctionDecl *D) { return true; } 560 static bool classof(const RecordDecl *D) { return true; } 561 static bool classof(const CXXRecordDecl *D) { return true; } 562 static bool classof(const EnumDecl *D) { return true; } 563 static bool classof(const ObjCMethodDecl *D) { return true; } 564 static bool classof(const ObjCInterfaceDecl *D) { return true; } 565 static bool classof(const ObjCCategoryDecl *D) { return true; } 566 static bool classof(const ObjCProtocolDecl *D) { return true; } 567 static bool classof(const ObjCImplementationDecl *D) { return true; } 568 static bool classof(const ObjCCategoryImplDecl *D) { return true; } 569 static bool classof(const LinkageSpecDecl *D) { return true; } 570 static bool classof(const BlockDecl *D) { return true; } 571 572private: 573 void insertImpl(ScopedDecl *D); 574 575 void EmitOutRec(llvm::Serializer& S) const; 576 void ReadOutRec(llvm::Deserializer& D, ASTContext& C); 577 578 friend class Decl; 579}; 580 581template<> struct DeclContext::KindTrait<DeclContext> { 582 static Decl::Kind getKind(const DeclContext *D) { return D->DeclKind; } 583}; 584 585inline bool Decl::isTemplateParameter() const { 586 return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm; 587} 588 589 590} // end clang. 591 592namespace llvm { 593 594/// Implement a isa_impl_wrap specialization to check whether a DeclContext is 595/// a specific Decl. 596template<class ToTy> 597struct isa_impl_wrap<ToTy, 598 const ::clang::DeclContext,const ::clang::DeclContext> { 599 static bool doit(const ::clang::DeclContext &Val) { 600 return ToTy::classof(::clang::Decl::castFromDeclContext(&Val)); 601 } 602}; 603template<class ToTy> 604struct isa_impl_wrap<ToTy, ::clang::DeclContext, ::clang::DeclContext> 605 : public isa_impl_wrap<ToTy, 606 const ::clang::DeclContext,const ::clang::DeclContext> {}; 607 608/// Implement cast_convert_val for Decl -> DeclContext conversions. 609template<class FromTy> 610struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> { 611 static ::clang::DeclContext &doit(const FromTy &Val) { 612 return *FromTy::castToDeclContext(&Val); 613 } 614}; 615 616template<class FromTy> 617struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> { 618 static ::clang::DeclContext *doit(const FromTy *Val) { 619 return FromTy::castToDeclContext(Val); 620 } 621}; 622 623template<class FromTy> 624struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> { 625 static const ::clang::DeclContext &doit(const FromTy &Val) { 626 return *FromTy::castToDeclContext(&Val); 627 } 628}; 629 630template<class FromTy> 631struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> { 632 static const ::clang::DeclContext *doit(const FromTy *Val) { 633 return FromTy::castToDeclContext(Val); 634 } 635}; 636 637/// Implement cast_convert_val for DeclContext -> Decl conversions. 638template<class ToTy> 639struct cast_convert_val<ToTy, 640 const ::clang::DeclContext,const ::clang::DeclContext> { 641 static ToTy &doit(const ::clang::DeclContext &Val) { 642 return *reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(&Val)); 643 } 644}; 645template<class ToTy> 646struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> 647 : public cast_convert_val<ToTy, 648 const ::clang::DeclContext,const ::clang::DeclContext> {}; 649 650template<class ToTy> 651struct cast_convert_val<ToTy, 652 const ::clang::DeclContext*, const ::clang::DeclContext*> { 653 static ToTy *doit(const ::clang::DeclContext *Val) { 654 return reinterpret_cast<ToTy*>(ToTy::castFromDeclContext(Val)); 655 } 656}; 657template<class ToTy> 658struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> 659 : public cast_convert_val<ToTy, 660 const ::clang::DeclContext*,const ::clang::DeclContext*> {}; 661 662} // end namespace llvm 663 664#endif 665