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/Basic/ABI.h"
24 /// GlobalDecl - represents a global declaration. This can either be a
25 /// CXXConstructorDecl and the constructor type (Base, Complete).
26 /// a CXXDestructorDecl and the destructor type (Base, Complete) or
27 /// a VarDecl, a FunctionDecl or a BlockDecl.
29 llvm::PointerIntPair<const Decl*, 2> Value;
31 void Init(const Decl *D) {
32 assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
33 assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
41 GlobalDecl(const VarDecl *D) { Init(D);}
42 GlobalDecl(const FunctionDecl *D) { Init(D); }
43 GlobalDecl(const BlockDecl *D) { Init(D); }
44 GlobalDecl(const CapturedDecl *D) { Init(D); }
45 GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
47 GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
49 GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
52 GlobalDecl getCanonicalDecl() const {
54 CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
55 CanonGD.Value.setInt(Value.getInt());
60 const Decl *getDecl() const { return Value.getPointer(); }
62 CXXCtorType getCtorType() const {
63 assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
64 return static_cast<CXXCtorType>(Value.getInt());
67 CXXDtorType getDtorType() const {
68 assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
69 return static_cast<CXXDtorType>(Value.getInt());
72 friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
73 return LHS.Value == RHS.Value;
76 void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
78 static GlobalDecl getFromOpaquePtr(void *P) {
80 GD.Value.setFromOpaqueValue(P);
84 GlobalDecl getWithDecl(const Decl *D) {
85 GlobalDecl Result(*this);
86 Result.Value.setPointer(D);
91 } // end namespace clang
94 template<class> struct DenseMapInfo;
96 template<> struct DenseMapInfo<clang::GlobalDecl> {
97 static inline clang::GlobalDecl getEmptyKey() {
98 return clang::GlobalDecl();
101 static inline clang::GlobalDecl getTombstoneKey() {
102 return clang::GlobalDecl::
103 getFromOpaquePtr(reinterpret_cast<void*>(-1));
106 static unsigned getHashValue(clang::GlobalDecl GD) {
107 return DenseMapInfo<void*>::getHashValue(GD.getAsOpaquePtr());
110 static bool isEqual(clang::GlobalDecl LHS,
111 clang::GlobalDecl RHS) {
117 // GlobalDecl isn't *technically* a POD type. However, its copy constructor,
118 // copy assignment operator, and destructor are all trivial.
120 struct isPodLike<clang::GlobalDecl> {
121 static const bool value = true;
123 } // end namespace llvm