[analyzer] Use the new registration mechanism on the non-path-sensitive-checkers:
[clang.git] / lib / CodeGen / GlobalDecl.h
blobc2f36d210bfcb68513882651185c3d45953bf437
1 //===--- GlobalDecl.h - Global declaration holder ---------------*- 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 // 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"
22 namespace clang {
24 namespace CodeGen {
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.
30 class GlobalDecl {
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!");
37 Value.setPointer(D);
40 public:
41 GlobalDecl() {}
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)
49 : Value(D, Type) {}
50 GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
51 : Value(D, Type) {}
53 GlobalDecl getCanonicalDecl() const {
54 GlobalDecl CanonGD;
55 CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
56 CanonGD.Value.setInt(Value.getInt());
58 return CanonGD;
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) {
80 GlobalDecl GD;
81 GD.Value.setFromOpaqueValue(P);
82 return GD;
85 GlobalDecl getWithDecl(const Decl *D) {
86 GlobalDecl Result(*this);
87 Result.Value.setPointer(D);
88 return Result;
92 } // end namespace CodeGen
93 } // end namespace clang
95 namespace llvm {
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) {
114 return LHS == RHS;
119 // GlobalDecl isn't *technically* a POD type. However, its copy constructor,
120 // copy assignment operator, and destructor are all trivial.
121 template <>
122 struct isPodLike<clang::CodeGen::GlobalDecl> {
123 static const bool value = true;
125 } // end namespace llvm
127 #endif