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 
23 namespace clang {
24 
25 /// GlobalDecl - represents a global declaration. This can either be a
26 /// CXXConstructorDecl and the constructor type (Base, Complete).
27 /// a CXXDestructorDecl and the destructor type (Base, Complete) or
28 /// a VarDecl, a FunctionDecl or a BlockDecl.
29 class GlobalDecl {
30  llvm::PointerIntPair<const Decl*, 2> Value;
31 
32  void Init(const Decl *D) {
33  assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
34  assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
35 
36  Value.setPointer(D);
37  }
38 
39 public:
41 
42  GlobalDecl(const VarDecl *D) { Init(D);}
43  GlobalDecl(const FunctionDecl *D) { Init(D); }
44  GlobalDecl(const BlockDecl *D) { Init(D); }
45  GlobalDecl(const CapturedDecl *D) { Init(D); }
46  GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
47  GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
48 
50  : Value(D, Type) {}
52  : Value(D, Type) {}
53 
55  GlobalDecl CanonGD;
56  CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
57  CanonGD.Value.setInt(Value.getInt());
58 
59  return CanonGD;
60  }
61 
62  const Decl *getDecl() const { return Value.getPointer(); }
63 
65  assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
66  return static_cast<CXXCtorType>(Value.getInt());
67  }
68 
70  assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
71  return static_cast<CXXDtorType>(Value.getInt());
72  }
73 
74  friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
75  return LHS.Value == RHS.Value;
76  }
77 
78  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
79 
80  static GlobalDecl getFromOpaquePtr(void *P) {
81  GlobalDecl GD;
82  GD.Value.setFromOpaqueValue(P);
83  return GD;
84  }
85 
87  GlobalDecl Result(*this);
88  Result.Value.setPointer(D);
89  return Result;
90  }
91 };
92 
93 } // end namespace clang
94 
95 namespace llvm {
96  template<class> struct DenseMapInfo;
97 
98  template<> struct DenseMapInfo<clang::GlobalDecl> {
99  static inline clang::GlobalDecl getEmptyKey() {
100  return clang::GlobalDecl();
101  }
102 
104  return clang::GlobalDecl::
105  getFromOpaquePtr(reinterpret_cast<void*>(-1));
106  }
107 
108  static unsigned getHashValue(clang::GlobalDecl GD) {
110  }
111 
112  static bool isEqual(clang::GlobalDecl LHS,
113  clang::GlobalDecl RHS) {
114  return LHS == RHS;
115  }
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 } // end namespace llvm
126 
127 #endif
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1631
GlobalDecl getWithDecl(const Decl *D)
Definition: GlobalDecl.h:86
GlobalDecl(const VarDecl *D)
Definition: GlobalDecl.h:42
CXXDtorType getDtorType() const
Definition: GlobalDecl.h:69
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
static clang::GlobalDecl getEmptyKey()
Definition: GlobalDecl.h:99
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
StringRef P
GlobalDecl getCanonicalDecl() const
Definition: GlobalDecl.h:54
The base class of the type hierarchy.
Definition: Type.h:1300
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2354
static GlobalDecl getFromOpaquePtr(void *P)
Definition: GlobalDecl.h:80
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:771
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:113
static bool isEqual(clang::GlobalDecl LHS, clang::GlobalDecl RHS)
Definition: GlobalDecl.h:112
void * getAsOpaquePtr() const
Definition: GlobalDecl.h:78
static unsigned getHashValue(clang::GlobalDecl GD)
Definition: GlobalDecl.h:108
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
Definition: GlobalDecl.h:51
GlobalDecl(const CapturedDecl *D)
Definition: GlobalDecl.h:45
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
Definition: GlobalDecl.h:49
CXXCtorType getCtorType() const
Definition: GlobalDecl.h:64
Enums/classes describing ABI related information about constructors, destructors and thunks...
GlobalDecl(const OMPDeclareReductionDecl *D)
Definition: GlobalDecl.h:47
This represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:3764
CXXDtorType
C++ destructor types.
Definition: ABI.h:34
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Definition: Decl.h:3595
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2576
The result type of a method or function.
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:29
static clang::GlobalDecl getTombstoneKey()
Definition: GlobalDecl.h:103
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:102
const Decl * getDecl() const
Definition: GlobalDecl.h:62
GlobalDecl(const ObjCMethodDecl *D)
Definition: GlobalDecl.h:46
GlobalDecl(const FunctionDecl *D)
Definition: GlobalDecl.h:43
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:44
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:74