clang  3.7.0
GlobalDecl.h
Go to the documentation of this file.
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.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_AST_GLOBALDECL_H
16 #define LLVM_CLANG_AST_GLOBALDECL_H
17 
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/Basic/ABI.h"
21 
22 namespace clang {
23 
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.
28 class GlobalDecl {
29  llvm::PointerIntPair<const Decl*, 2> Value;
30 
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!");
34 
35  Value.setPointer(D);
36  }
37 
38 public:
40 
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); }
46 
48  : Value(D, Type) {}
50  : Value(D, Type) {}
51 
53  GlobalDecl CanonGD;
54  CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
55  CanonGD.Value.setInt(Value.getInt());
56 
57  return CanonGD;
58  }
59 
60  const Decl *getDecl() const { return Value.getPointer(); }
61 
63  assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
64  return static_cast<CXXCtorType>(Value.getInt());
65  }
66 
68  assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
69  return static_cast<CXXDtorType>(Value.getInt());
70  }
71 
72  friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
73  return LHS.Value == RHS.Value;
74  }
75 
76  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
77 
78  static GlobalDecl getFromOpaquePtr(void *P) {
79  GlobalDecl GD;
80  GD.Value.setFromOpaqueValue(P);
81  return GD;
82  }
83 
85  GlobalDecl Result(*this);
86  Result.Value.setPointer(D);
87  return Result;
88  }
89 };
90 
91 } // end namespace clang
92 
93 namespace llvm {
94  template<class> struct DenseMapInfo;
95 
96  template<> struct DenseMapInfo<clang::GlobalDecl> {
97  static inline clang::GlobalDecl getEmptyKey() {
98  return clang::GlobalDecl();
99  }
100 
102  return clang::GlobalDecl::
103  getFromOpaquePtr(reinterpret_cast<void*>(-1));
104  }
105 
106  static unsigned getHashValue(clang::GlobalDecl GD) {
108  }
109 
110  static bool isEqual(clang::GlobalDecl LHS,
111  clang::GlobalDecl RHS) {
112  return LHS == RHS;
113  }
114 
115  };
116 
117  // GlobalDecl isn't *technically* a POD type. However, its copy constructor,
118  // copy assignment operator, and destructor are all trivial.
119  template <>
120  struct isPodLike<clang::GlobalDecl> {
121  static const bool value = true;
122  };
123 } // end namespace llvm
124 
125 #endif
GlobalDecl getWithDecl(const Decl *D)
Definition: GlobalDecl.h:84
CXXCtorType getCtorType() const
Definition: GlobalDecl.h:62
GlobalDecl(const VarDecl *D)
Definition: GlobalDecl.h:41
static clang::GlobalDecl getEmptyKey()
Definition: GlobalDecl.h:97
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2147
static GlobalDecl getFromOpaquePtr(void *P)
Definition: GlobalDecl.h:78
GlobalDecl getCanonicalDecl() const
Definition: GlobalDecl.h:52
static bool isEqual(clang::GlobalDecl LHS, clang::GlobalDecl RHS)
Definition: GlobalDecl.h:110
static unsigned getHashValue(clang::GlobalDecl GD)
Definition: GlobalDecl.h:106
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
Definition: GlobalDecl.h:49
GlobalDecl(const CapturedDecl *D)
Definition: GlobalDecl.h:44
const Decl * getDecl() const
Definition: GlobalDecl.h:60
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
Definition: GlobalDecl.h:47
Enums/classes describing ABI related information about constructors, destructors and thunks...
This represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:3616
AnnotatingParser & P
void * getAsOpaquePtr() const
Definition: GlobalDecl.h:76
CXXDtorType
C++ destructor types.
Definition: ABI.h:34
CXXDtorType getDtorType() const
Definition: GlobalDecl.h:67
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2358
The result type of a method or function.
static clang::GlobalDecl getTombstoneKey()
Definition: GlobalDecl.h:101
GlobalDecl(const ObjCMethodDecl *D)
Definition: GlobalDecl.h:45
GlobalDecl(const FunctionDecl *D)
Definition: GlobalDecl.h:42
CXXCtorType
C++ constructor types.
Definition: ABI.h:25
GlobalDecl(const BlockDecl *D)
Definition: GlobalDecl.h:43
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS)
Definition: GlobalDecl.h:72