clang  8.0.0svn
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/AST/DeclOpenMP.h"
21 #include "clang/Basic/ABI.h"
22 #include "clang/Basic/LLVM.h"
23 #include "llvm/ADT/DenseMapInfo.h"
24 #include "llvm/ADT/PointerIntPair.h"
25 #include "llvm/Support/Casting.h"
26 #include "llvm/Support/type_traits.h"
27 #include <cassert>
28 
29 namespace clang {
30 
31 /// GlobalDecl - represents a global declaration. This can either be a
32 /// CXXConstructorDecl and the constructor type (Base, Complete).
33 /// a CXXDestructorDecl and the destructor type (Base, Complete) or
34 /// a VarDecl, a FunctionDecl or a BlockDecl.
35 class GlobalDecl {
36  llvm::PointerIntPair<const Decl *, 2> Value;
37  unsigned MultiVersionIndex = 0;
38 
39  void Init(const Decl *D) {
40  assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
41  assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
42 
43  Value.setPointer(D);
44  }
45 
46 public:
47  GlobalDecl() = default;
48  GlobalDecl(const VarDecl *D) { Init(D);}
49  GlobalDecl(const FunctionDecl *D, unsigned MVIndex = 0)
50  : MultiVersionIndex(MVIndex) {
51  Init(D);
52  }
53  GlobalDecl(const BlockDecl *D) { Init(D); }
54  GlobalDecl(const CapturedDecl *D) { Init(D); }
55  GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
56  GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
57  GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
58  GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
59 
61  GlobalDecl CanonGD;
62  CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
63  CanonGD.Value.setInt(Value.getInt());
64  CanonGD.MultiVersionIndex = MultiVersionIndex;
65 
66  return CanonGD;
67  }
68 
69  const Decl *getDecl() const { return Value.getPointer(); }
70 
72  assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
73  return static_cast<CXXCtorType>(Value.getInt());
74  }
75 
77  assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
78  return static_cast<CXXDtorType>(Value.getInt());
79  }
80 
81  unsigned getMultiVersionIndex() const {
82  assert(isa<FunctionDecl>(getDecl()) &&
83  !isa<CXXConstructorDecl>(getDecl()) &&
84  !isa<CXXDestructorDecl>(getDecl()) &&
85  "Decl is not a plain FunctionDecl!");
86  return MultiVersionIndex;
87  }
88 
89  friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
90  return LHS.Value == RHS.Value &&
91  LHS.MultiVersionIndex == RHS.MultiVersionIndex;
92  }
93 
94  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
95 
96  static GlobalDecl getFromOpaquePtr(void *P) {
97  GlobalDecl GD;
98  GD.Value.setFromOpaqueValue(P);
99  return GD;
100  }
101 
103  GlobalDecl Result(*this);
104  Result.Value.setPointer(D);
105  return Result;
106  }
107 
109  assert(isa<FunctionDecl>(getDecl()) &&
110  !isa<CXXConstructorDecl>(getDecl()) &&
111  !isa<CXXDestructorDecl>(getDecl()) &&
112  "Decl is not a plain FunctionDecl!");
113  GlobalDecl Result(*this);
114  Result.MultiVersionIndex = Index;
115  return Result;
116  }
117 };
118 
119 } // namespace clang
120 
121 namespace llvm {
122 
123  template<> struct DenseMapInfo<clang::GlobalDecl> {
124  static inline clang::GlobalDecl getEmptyKey() {
125  return clang::GlobalDecl();
126  }
127 
129  return clang::GlobalDecl::
130  getFromOpaquePtr(reinterpret_cast<void*>(-1));
131  }
132 
133  static unsigned getHashValue(clang::GlobalDecl GD) {
135  }
136 
137  static bool isEqual(clang::GlobalDecl LHS,
138  clang::GlobalDecl RHS) {
139  return LHS == RHS;
140  }
141  };
142 
143  // GlobalDecl isn't *technically* a POD type. However, its copy constructor,
144  // copy assignment operator, and destructor are all trivial.
145  template <>
147  static const bool value = true;
148  };
149 
150 } // namespace llvm
151 
152 #endif // LLVM_CLANG_AST_GLOBALDECL_H
Represents a function declaration or definition.
Definition: Decl.h:1739
GlobalDecl getWithDecl(const Decl *D)
Definition: GlobalDecl.h:102
GlobalDecl(const VarDecl *D)
Definition: GlobalDecl.h:48
GlobalDecl getWithMultiVersionIndex(unsigned Index)
Definition: GlobalDecl.h:108
CXXDtorType getDtorType() const
Definition: GlobalDecl.h:76
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
static clang::GlobalDecl getEmptyKey()
Definition: GlobalDecl.h:124
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
StringRef P
GlobalDecl getCanonicalDecl() const
Definition: GlobalDecl.h:60
The base class of the type hierarchy.
Definition: Type.h:1415
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2481
static GlobalDecl getFromOpaquePtr(void *P)
Definition: GlobalDecl.h:96
Represents a variable declaration or definition.
Definition: Decl.h:812
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
GlobalDecl()=default
static bool isEqual(clang::GlobalDecl LHS, clang::GlobalDecl RHS)
Definition: GlobalDecl.h:137
void * getAsOpaquePtr() const
Definition: GlobalDecl.h:94
static unsigned getHashValue(clang::GlobalDecl GD)
Definition: GlobalDecl.h:133
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
Definition: GlobalDecl.h:58
GlobalDecl(const CapturedDecl *D)
Definition: GlobalDecl.h:54
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
Definition: GlobalDecl.h:57
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
CXXCtorType getCtorType() const
Definition: GlobalDecl.h:71
Enums/classes describing ABI related information about constructors, destructors and thunks...
GlobalDecl(const OMPDeclareReductionDecl *D)
Definition: GlobalDecl.h:56
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4053
GlobalDecl(const FunctionDecl *D, unsigned MVIndex=0)
Definition: GlobalDecl.h:49
CXXDtorType
C++ destructor types.
Definition: ABI.h:34
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:3867
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2703
The result type of a method or function.
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:35
static clang::GlobalDecl getTombstoneKey()
Definition: GlobalDecl.h:128
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:103
const Decl * getDecl() const
Definition: GlobalDecl.h:69
GlobalDecl(const ObjCMethodDecl *D)
Definition: GlobalDecl.h:55
This file defines OpenMP nodes for declarative directives.
CXXCtorType
C++ constructor types.
Definition: ABI.h:25
Dataflow Directional Tag Classes.
unsigned getMultiVersionIndex() const
Definition: GlobalDecl.h:81
GlobalDecl(const BlockDecl *D)
Definition: GlobalDecl.h:53
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:89