Coverage Report

Created: 2018-09-25 23:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/GlobalDecl.h
Line
Count
Source
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
6.19M
  void Init(const Decl *D) {
39
6.19M
    assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
40
6.19M
    assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
41
6.19M
42
6.19M
    Value.setPointer(D);
43
6.19M
  }
44
45
public:
46
27.5M
  GlobalDecl() = default;
47
1.50M
  GlobalDecl(const VarDecl *D) { Init(D);}
48
4.64M
  GlobalDecl(const FunctionDecl *D) { Init(D); }
49
4.36k
  GlobalDecl(const BlockDecl *D) { Init(D); }
50
41.6k
  GlobalDecl(const CapturedDecl *D) { Init(D); }
51
4.49k
  GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
52
6
  GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
53
890k
  GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
54
397k
  GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
55
56
4.22M
  GlobalDecl getCanonicalDecl() const {
57
4.22M
    GlobalDecl CanonGD;
58
4.22M
    CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
59
4.22M
    CanonGD.Value.setInt(Value.getInt());
60
4.22M
61
4.22M
    return CanonGD;
62
4.22M
  }
63
64
28.6M
  const Decl *getDecl() const { return Value.getPointer(); }
65
66
433k
  CXXCtorType getCtorType() const {
67
433k
    assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
68
433k
    return static_cast<CXXCtorType>(Value.getInt());
69
433k
  }
70
71
397k
  CXXDtorType getDtorType() const {
72
397k
    assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
73
397k
    return static_cast<CXXDtorType>(Value.getInt());
74
397k
  }
75
76
57.6M
  friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
77
57.6M
    return LHS.Value == RHS.Value;
78
57.6M
  }
79
80
8.98M
  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
81
82
9.06M
  static GlobalDecl getFromOpaquePtr(void *P) {
83
9.06M
    GlobalDecl GD;
84
9.06M
    GD.Value.setFromOpaqueValue(P);
85
9.06M
    return GD;
86
9.06M
  }
87
88
15.1k
  GlobalDecl getWithDecl(const Decl *D) {
89
15.1k
    GlobalDecl Result(*this);
90
15.1k
    Result.Value.setPointer(D);
91
15.1k
    return Result;
92
15.1k
  }
93
};
94
95
} // namespace clang
96
97
namespace llvm {
98
99
  template<> struct DenseMapInfo<clang::GlobalDecl> {
100
11.1M
    static inline clang::GlobalDecl getEmptyKey() {
101
11.1M
      return clang::GlobalDecl();
102
11.1M
    }
103
104
9.06M
    static inline clang::GlobalDecl getTombstoneKey() {
105
9.06M
      return clang::GlobalDecl::
106
9.06M
        getFromOpaquePtr(reinterpret_cast<void*>(-1));
107
9.06M
    }
108
109
8.98M
    static unsigned getHashValue(clang::GlobalDecl GD) {
110
8.98M
      return DenseMapInfo<void*>::getHashValue(GD.getAsOpaquePtr());
111
8.98M
    }
112
113
    static bool isEqual(clang::GlobalDecl LHS,
114
57.6M
                        clang::GlobalDecl RHS) {
115
57.6M
      return LHS == RHS;
116
57.6M
    }
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 <>
122
  struct isPodLike<clang::GlobalDecl> {
123
    static const bool value = true;
124
  };
125
126
} // namespace llvm
127
128
#endif // LLVM_CLANG_AST_GLOBALDECL_H