1 //===--- GlobalDecl.h - Global declaration holder ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // A GlobalDecl can hold either a regular variable/function or a C++ ctor/dtor
11 // together with its type.
13 //===----------------------------------------------------------------------===//
15 #ifndef CLANG_CODEGEN_GLOBALDECL_H
16 #define CLANG_CODEGEN_GLOBALDECL_H
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/Basic/ABI.h"
26 /// GlobalDecl - represents a global declaration. This can either be a
27 /// CXXConstructorDecl and the constructor type (Base, Complete).
28 /// a CXXDestructorDecl and the destructor type (Base, Complete) or
29 /// a VarDecl, a FunctionDecl or a BlockDecl.
31 llvm::PointerIntPair
<const Decl
*, 2> Value
;
33 void Init(const Decl
*D
) {
34 assert(!isa
<CXXConstructorDecl
>(D
) && "Use other ctor with ctor decls!");
35 assert(!isa
<CXXDestructorDecl
>(D
) && "Use other ctor with dtor decls!");
43 GlobalDecl(const VarDecl
*D
) { Init(D
);}
44 GlobalDecl(const FunctionDecl
*D
) { Init(D
); }
45 GlobalDecl(const BlockDecl
*D
) { Init(D
); }
46 GlobalDecl(const ObjCMethodDecl
*D
) { Init(D
); }
48 GlobalDecl(const CXXConstructorDecl
*D
, CXXCtorType Type
)
50 GlobalDecl(const CXXDestructorDecl
*D
, CXXDtorType Type
)
53 GlobalDecl
getCanonicalDecl() const {
55 CanonGD
.Value
.setPointer(Value
.getPointer()->getCanonicalDecl());
56 CanonGD
.Value
.setInt(Value
.getInt());
61 const Decl
*getDecl() const { return Value
.getPointer(); }
63 CXXCtorType
getCtorType() const {
64 assert(isa
<CXXConstructorDecl
>(getDecl()) && "Decl is not a ctor!");
65 return static_cast<CXXCtorType
>(Value
.getInt());
68 CXXDtorType
getDtorType() const {
69 assert(isa
<CXXDestructorDecl
>(getDecl()) && "Decl is not a dtor!");
70 return static_cast<CXXDtorType
>(Value
.getInt());
73 friend bool operator==(const GlobalDecl
&LHS
, const GlobalDecl
&RHS
) {
74 return LHS
.Value
== RHS
.Value
;
77 void *getAsOpaquePtr() const { return Value
.getOpaqueValue(); }
79 static GlobalDecl
getFromOpaquePtr(void *P
) {
81 GD
.Value
.setFromOpaqueValue(P
);
85 GlobalDecl
getWithDecl(const Decl
*D
) {
86 GlobalDecl
Result(*this);
87 Result
.Value
.setPointer(D
);
92 } // end namespace CodeGen
93 } // end namespace clang
96 template<class> struct DenseMapInfo
;
98 template<> struct DenseMapInfo
<clang::CodeGen::GlobalDecl
> {
99 static inline clang::CodeGen::GlobalDecl
getEmptyKey() {
100 return clang::CodeGen::GlobalDecl();
103 static inline clang::CodeGen::GlobalDecl
getTombstoneKey() {
104 return clang::CodeGen::GlobalDecl::
105 getFromOpaquePtr(reinterpret_cast<void*>(-1));
108 static unsigned getHashValue(clang::CodeGen::GlobalDecl GD
) {
109 return DenseMapInfo
<void*>::getHashValue(GD
.getAsOpaquePtr());
112 static bool isEqual(clang::CodeGen::GlobalDecl LHS
,
113 clang::CodeGen::GlobalDecl RHS
) {
119 // GlobalDecl isn't *technically* a POD type. However, its copy constructor,
120 // copy assignment operator, and destructor are all trivial.
122 struct isPodLike
<clang::CodeGen::GlobalDecl
> {
123 static const bool value
= true;
125 } // end namespace llvm