| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_BASIC_VISIBILITY_H |
| 15 | #define LLVM_CLANG_BASIC_VISIBILITY_H |
| 16 | |
| 17 | #include "clang/Basic/Linkage.h" |
| 18 | #include <cassert> |
| 19 | #include <cstdint> |
| 20 | |
| 21 | namespace clang { |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | enum Visibility { |
| 34 | |
| 35 | |
| 36 | HiddenVisibility, |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | ProtectedVisibility, |
| 42 | |
| 43 | |
| 44 | |
| 45 | DefaultVisibility |
| 46 | }; |
| 47 | |
| 48 | inline Visibility minVisibility(Visibility L, Visibility R) { |
| 49 | return L < R ? L : R; |
| 50 | } |
| 51 | |
| 52 | class LinkageInfo { |
| 53 | uint8_t linkage_ : 3; |
| 54 | uint8_t visibility_ : 2; |
| 55 | uint8_t explicit_ : 1; |
| 56 | |
| 57 | void setVisibility(Visibility V, bool E) { visibility_ = V; explicit_ = E; } |
| 58 | public: |
| 59 | LinkageInfo() : linkage_(ExternalLinkage), visibility_(DefaultVisibility), |
| 60 | explicit_(false) {} |
| 61 | LinkageInfo(Linkage L, Visibility V, bool E) |
| 62 | : linkage_(L), visibility_(V), explicit_(E) { |
| 63 | (0) . __assert_fail ("getLinkage() == L && getVisibility() == V && isVisibilityExplicit() == E && \"Enum truncated!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Visibility.h", 64, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(getLinkage() == L && getVisibility() == V && |
| 64 | (0) . __assert_fail ("getLinkage() == L && getVisibility() == V && isVisibilityExplicit() == E && \"Enum truncated!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Basic/Visibility.h", 64, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> isVisibilityExplicit() == E && "Enum truncated!"); |
| 65 | } |
| 66 | |
| 67 | static LinkageInfo external() { |
| 68 | return LinkageInfo(); |
| 69 | } |
| 70 | static LinkageInfo internal() { |
| 71 | return LinkageInfo(InternalLinkage, DefaultVisibility, false); |
| 72 | } |
| 73 | static LinkageInfo uniqueExternal() { |
| 74 | return LinkageInfo(UniqueExternalLinkage, DefaultVisibility, false); |
| 75 | } |
| 76 | static LinkageInfo none() { |
| 77 | return LinkageInfo(NoLinkage, DefaultVisibility, false); |
| 78 | } |
| 79 | static LinkageInfo visible_none() { |
| 80 | return LinkageInfo(VisibleNoLinkage, DefaultVisibility, false); |
| 81 | } |
| 82 | |
| 83 | Linkage getLinkage() const { return (Linkage)linkage_; } |
| 84 | Visibility getVisibility() const { return (Visibility)visibility_; } |
| 85 | bool isVisibilityExplicit() const { return explicit_; } |
| 86 | |
| 87 | void setLinkage(Linkage L) { linkage_ = L; } |
| 88 | |
| 89 | void mergeLinkage(Linkage L) { |
| 90 | setLinkage(minLinkage(getLinkage(), L)); |
| 91 | } |
| 92 | void mergeLinkage(LinkageInfo other) { |
| 93 | mergeLinkage(other.getLinkage()); |
| 94 | } |
| 95 | |
| 96 | void mergeExternalVisibility(Linkage L) { |
| 97 | Linkage ThisL = getLinkage(); |
| 98 | if (!isExternallyVisible(L)) { |
| 99 | if (ThisL == VisibleNoLinkage) |
| 100 | ThisL = NoLinkage; |
| 101 | else if (ThisL == ExternalLinkage) |
| 102 | ThisL = UniqueExternalLinkage; |
| 103 | } |
| 104 | setLinkage(ThisL); |
| 105 | } |
| 106 | void mergeExternalVisibility(LinkageInfo Other) { |
| 107 | mergeExternalVisibility(Other.getLinkage()); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | void mergeVisibility(Visibility newVis, bool newExplicit) { |
| 112 | Visibility oldVis = getVisibility(); |
| 113 | |
| 114 | |
| 115 | if (oldVis < newVis) |
| 116 | return; |
| 117 | |
| 118 | |
| 119 | |
| 120 | if (oldVis == newVis && !newExplicit) |
| 121 | return; |
| 122 | |
| 123 | |
| 124 | |
| 125 | setVisibility(newVis, newExplicit); |
| 126 | } |
| 127 | void mergeVisibility(LinkageInfo other) { |
| 128 | mergeVisibility(other.getVisibility(), other.isVisibilityExplicit()); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | void merge(LinkageInfo other) { |
| 133 | mergeLinkage(other); |
| 134 | mergeVisibility(other); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | void mergeMaybeWithVisibility(LinkageInfo other, bool withVis) { |
| 139 | mergeLinkage(other); |
| 140 | if (withVis) mergeVisibility(other); |
| 141 | } |
| 142 | }; |
| 143 | } |
| 144 | |
| 145 | #endif |
| 146 | |