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