clang  6.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 
38  void Init(const Decl *D) {
39  assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
40  assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
41 
42  Value.setPointer(D);
43  }
44 
45 public:
46  GlobalDecl() = default;
47  GlobalDecl(const VarDecl *D) { Init(D);}
48  GlobalDecl(const FunctionDecl *D) { Init(D); }
49  GlobalDecl(const BlockDecl *D) { Init(D); }
50  GlobalDecl(const CapturedDecl *D) { Init(D); }
51  GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
52  GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
53  GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
54  GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
55 
57  GlobalDecl CanonGD;
58  CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
59  CanonGD.Value.setInt(Value.getInt());
60 
61  return CanonGD;
62  }
63 
64  const Decl *getDecl() const { return Value.getPointer(); }
65 
67  assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
68  return static_cast<CXXCtorType>(Value.getInt());
69  }
70 
72  assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
73  return static_cast<CXXDtorType>(Value.getInt());
74  }
75 
76  friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
77  return LHS.Value == RHS.Value;
78  }
79 
80  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
81 
82  static GlobalDecl getFromOpaquePtr(void *P) {
83  GlobalDecl GD;
84  GD.Value.setFromOpaqueValue(P);
85  return GD;
86  }
87 
89  GlobalDecl Result(*this);
90  Result.Value.setPointer(D);
91  return Result;
92  }
93 };
94 
95 } // namespace clang
96 
97 namespace llvm {
98 
99  template<> struct DenseMapInfo<clang::GlobalDecl> {
100  static inline clang::GlobalDecl getEmptyKey() {
101  return clang::GlobalDecl();
102  }
103 
105  return clang::GlobalDecl::
106  getFromOpaquePtr(reinterpret_cast<void*>(-1));
107  }
108 
109  static unsigned getHashValue(clang::GlobalDecl GD) {
111  }
112 
113  static bool isEqual(clang::GlobalDecl LHS,
114  clang::GlobalDecl RHS) {
115  return LHS == RHS;
116  }
117  };
118 
119  // GlobalDecl isn't *technically* a POD type. However, its copy constructor,
120  // copy assignment operator, and destructor are all trivial.
121  template <>
123  static const bool value = true;
124  };
125 
126 } // namespace llvm
127 
128 #endif // LLVM_CLANG_AST_GLOBALDECL_H
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
GlobalDecl getWithDecl(const Decl *D)
Definition: GlobalDecl.h:88
GlobalDecl(const VarDecl *D)
Definition: GlobalDecl.h:47
CXXDtorType getDtorType() const
Definition: GlobalDecl.h:71
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
static clang::GlobalDecl getEmptyKey()
Definition: GlobalDecl.h:100
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
StringRef P
GlobalDecl getCanonicalDecl() const
Definition: GlobalDecl.h:56
The base class of the type hierarchy.
Definition: Type.h:1353
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2397
static GlobalDecl getFromOpaquePtr(void *P)
Definition: GlobalDecl.h:82
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:807
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:113
void * getAsOpaquePtr() const
Definition: GlobalDecl.h:80
static unsigned getHashValue(clang::GlobalDecl GD)
Definition: GlobalDecl.h:109
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
Definition: GlobalDecl.h:54
GlobalDecl(const CapturedDecl *D)
Definition: GlobalDecl.h:50
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
Definition: GlobalDecl.h:53
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
CXXCtorType getCtorType() const
Definition: GlobalDecl.h:66
Enums/classes describing ABI related information about constructors, destructors and thunks...
GlobalDecl(const OMPDeclareReductionDecl *D)
Definition: GlobalDecl.h:52
This represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:3860
CXXDtorType
C++ destructor types.
Definition: ABI.h:34
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Definition: Decl.h:3689
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2620
The result type of a method or function.
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:35
static clang::GlobalDecl getTombstoneKey()
Definition: GlobalDecl.h:104
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:102
const Decl * getDecl() const
Definition: GlobalDecl.h:64
GlobalDecl(const ObjCMethodDecl *D)
Definition: GlobalDecl.h:51
GlobalDecl(const FunctionDecl *D)
Definition: GlobalDecl.h:48
This file defines OpenMP nodes for declarative directives.
CXXCtorType
C++ constructor types.
Definition: ABI.h:25
Dataflow Directional Tag Classes.
GlobalDecl(const BlockDecl *D)
Definition: GlobalDecl.h:49
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:76