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 LLVM_CLANG_AST_GLOBALDECL_H
16 #define LLVM_CLANG_AST_GLOBALDECL_H
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclOpenMP.h"
21 #include "clang/Basic/ABI.h"
25 /// GlobalDecl - represents a global declaration. This can either be a
26 /// CXXConstructorDecl and the constructor type (Base, Complete).
27 /// a CXXDestructorDecl and the destructor type (Base, Complete) or
28 /// a VarDecl, a FunctionDecl or a BlockDecl.
30 llvm::PointerIntPair<const Decl*, 2> Value;
32 void Init(const Decl *D) {
33 assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
34 assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
42 GlobalDecl(const VarDecl *D) { Init(D);}
43 GlobalDecl(const FunctionDecl *D) { Init(D); }
44 GlobalDecl(const BlockDecl *D) { Init(D); }
45 GlobalDecl(const CapturedDecl *D) { Init(D); }
46 GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
47 GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
49 GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
51 GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
54 GlobalDecl getCanonicalDecl() const {
56 CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
57 CanonGD.Value.setInt(Value.getInt());
62 const Decl *getDecl() const { return Value.getPointer(); }
64 CXXCtorType getCtorType() const {
65 assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
66 return static_cast<CXXCtorType>(Value.getInt());
69 CXXDtorType getDtorType() const {
70 assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
71 return static_cast<CXXDtorType>(Value.getInt());
74 friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
75 return LHS.Value == RHS.Value;
78 void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
80 static GlobalDecl getFromOpaquePtr(void *P) {
82 GD.Value.setFromOpaqueValue(P);
86 GlobalDecl getWithDecl(const Decl *D) {
87 GlobalDecl Result(*this);
88 Result.Value.setPointer(D);
93 } // end namespace clang
96 template<class> struct DenseMapInfo;
98 template<> struct DenseMapInfo<clang::GlobalDecl> {
99 static inline clang::GlobalDecl getEmptyKey() {
100 return clang::GlobalDecl();
103 static inline clang::GlobalDecl getTombstoneKey() {
104 return clang::GlobalDecl::
105 getFromOpaquePtr(reinterpret_cast<void*>(-1));
108 static unsigned getHashValue(clang::GlobalDecl GD) {
109 return DenseMapInfo<void*>::getHashValue(GD.getAsOpaquePtr());
112 static bool isEqual(clang::GlobalDecl LHS,
113 clang::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::GlobalDecl> {
123 static const bool value = true;
125 } // end namespace llvm