Coverage Report

Created: 2018-09-21 05:35

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/Visibility.h
Line
Count
Source (jump to first uncovered line)
1
//===--- Visibility.h - Visibility enumeration and utilities ----*- 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
/// \file
11
/// Defines the clang::Visibility enumeration and various utility
12
/// functions.
13
///
14
//===----------------------------------------------------------------------===//
15
#ifndef LLVM_CLANG_BASIC_VISIBILITY_H
16
#define LLVM_CLANG_BASIC_VISIBILITY_H
17
18
#include "clang/Basic/Linkage.h"
19
#include <cassert>
20
#include <cstdint>
21
22
namespace clang {
23
24
/// Describes the different kinds of visibility that a declaration
25
/// may have.
26
///
27
/// Visibility determines how a declaration interacts with the dynamic
28
/// linker.  It may also affect whether the symbol can be found by runtime
29
/// symbol lookup APIs.
30
///
31
/// Visibility is not described in any language standard and
32
/// (nonetheless) sometimes has odd behavior.  Not all platforms
33
/// support all visibility kinds.
34
enum Visibility {
35
  /// Objects with "hidden" visibility are not seen by the dynamic
36
  /// linker.
37
  HiddenVisibility,
38
39
  /// Objects with "protected" visibility are seen by the dynamic
40
  /// linker but always dynamically resolve to an object within this
41
  /// shared object.
42
  ProtectedVisibility,
43
44
  /// Objects with "default" visibility are seen by the dynamic linker
45
  /// and act like normal objects.
46
  DefaultVisibility
47
};
48
49
inline Visibility minVisibility(Visibility L, Visibility R) {
50
  return L < R ? L : R;
51
}
52
53
class LinkageInfo {
54
  uint8_t linkage_    : 3;
55
  uint8_t visibility_ : 2;
56
  uint8_t explicit_   : 1;
57
58
3.61M
  void setVisibility(Visibility V, bool E) { visibility_ = V; explicit_ = E; }
59
public:
60
  LinkageInfo() : linkage_(ExternalLinkage), visibility_(DefaultVisibility),
61
24.3M
                  explicit_(false) {}
62
  LinkageInfo(Linkage L, Visibility V, bool E)
63
48.1M
    : linkage_(L), visibility_(V), explicit_(E) {
64
48.1M
    assert(getLinkage() == L && getVisibility() == V &&
65
48.1M
           isVisibilityExplicit() == E && "Enum truncated!");
66
48.1M
  }
67
68
7.82M
  static LinkageInfo external() {
69
7.82M
    return LinkageInfo();
70
7.82M
  }
71
1.08M
  static LinkageInfo internal() {
72
1.08M
    return LinkageInfo(InternalLinkage, DefaultVisibility, false);
73
1.08M
  }
74
2.28k
  static LinkageInfo uniqueExternal() {
75
2.28k
    return LinkageInfo(UniqueExternalLinkage, DefaultVisibility, false);
76
2.28k
  }
77
1.43M
  static LinkageInfo none() {
78
1.43M
    return LinkageInfo(NoLinkage, DefaultVisibility, false);
79
1.43M
  }
80
1
  static LinkageInfo visible_none() {
81
1
    return LinkageInfo(VisibleNoLinkage, DefaultVisibility, false);
82
1
  }
83
84
88.7M
  Linkage getLinkage() const { return (Linkage)linkage_; }
85
19.2M
  Visibility getVisibility() const { return (Visibility)visibility_; }
86
14.5M
  bool isVisibilityExplicit() const { return explicit_; }
87
88
8.53M
  void setLinkage(Linkage L) { linkage_ = L; }
89
90
6.93M
  void mergeLinkage(Linkage L) {
91
6.93M
    setLinkage(minLinkage(getLinkage(), L));
92
6.93M
  }
93
6.93M
  void mergeLinkage(LinkageInfo other) {
94
6.93M
    mergeLinkage(other.getLinkage());
95
6.93M
  }
96
97
1.59M
  void mergeExternalVisibility(Linkage L) {
98
1.59M
    Linkage ThisL = getLinkage();
99
1.59M
    if (!isExternallyVisible(L)) {
100
2.23k
      if (ThisL == VisibleNoLinkage)
101
0
        ThisL = NoLinkage;
102
2.23k
      else if (ThisL == ExternalLinkage)
103
2.23k
        ThisL = UniqueExternalLinkage;
104
2.23k
    }
105
1.59M
    setLinkage(ThisL);
106
1.59M
  }
107
1.59M
  void mergeExternalVisibility(LinkageInfo Other) {
108
1.59M
    mergeExternalVisibility(Other.getLinkage());
109
1.59M
  }
110
111
  /// Merge in the visibility 'newVis'.
112
10.6M
  void mergeVisibility(Visibility newVis, bool newExplicit) {
113
10.6M
    Visibility oldVis = getVisibility();
114
10.6M
115
10.6M
    // Never increase visibility.
116
10.6M
    if (oldVis < newVis)
117
544k
      return;
118
10.1M
119
10.1M
    // If the new visibility is the same as the old and the new
120
10.1M
    // visibility isn't explicit, we have nothing to add.
121
10.1M
    if (oldVis == newVis && 
!newExplicit8.89M
)
122
6.53M
      return;
123
3.61M
124
3.61M
    // Otherwise, we're either decreasing visibility or making our
125
3.61M
    // existing visibility explicit.
126
3.61M
    setVisibility(newVis, newExplicit);
127
3.61M
  }
128
8.02M
  void mergeVisibility(LinkageInfo other) {
129
8.02M
    mergeVisibility(other.getVisibility(), other.isVisibilityExplicit());
130
8.02M
  }
131
132
  /// Merge both linkage and visibility.
133
3.01M
  void merge(LinkageInfo other) {
134
3.01M
    mergeLinkage(other);
135
3.01M
    mergeVisibility(other);
136
3.01M
  }
137
138
  /// Merge linkage and conditionally merge visibility.
139
3.91M
  void mergeMaybeWithVisibility(LinkageInfo other, bool withVis) {
140
3.91M
    mergeLinkage(other);
141
3.91M
    if (withVis) 
mergeVisibility(other)3.44M
;
142
3.91M
  }
143
};
144
}
145
146
#endif // LLVM_CLANG_BASIC_VISIBILITY_H