| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_LIB_AST_LINKAGE_H |
| 15 | #define LLVM_CLANG_LIB_AST_LINKAGE_H |
| 16 | |
| 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/DeclCXX.h" |
| 19 | #include "clang/AST/Type.h" |
| 20 | #include "llvm/ADT/DenseMap.h" |
| 21 | #include "llvm/ADT/Optional.h" |
| 22 | #include "llvm/ADT/PointerIntPair.h" |
| 23 | |
| 24 | namespace clang { |
| 25 | |
| 26 | |
| 27 | |
| 28 | struct LVComputationKind { |
| 29 | |
| 30 | |
| 31 | unsigned ExplicitKind : 1; |
| 32 | |
| 33 | |
| 34 | unsigned IgnoreExplicitVisibility : 1; |
| 35 | |
| 36 | |
| 37 | unsigned IgnoreAllVisibility : 1; |
| 38 | |
| 39 | enum { NumLVComputationKindBits = 3 }; |
| 40 | |
| 41 | explicit LVComputationKind(NamedDecl::ExplicitVisibilityKind EK) |
| 42 | : ExplicitKind(EK), IgnoreExplicitVisibility(false), |
| 43 | IgnoreAllVisibility(false) {} |
| 44 | |
| 45 | NamedDecl::ExplicitVisibilityKind getExplicitVisibilityKind() const { |
| 46 | return static_cast<NamedDecl::ExplicitVisibilityKind>(ExplicitKind); |
| 47 | } |
| 48 | |
| 49 | bool isTypeVisibility() const { |
| 50 | return getExplicitVisibilityKind() == NamedDecl::VisibilityForType; |
| 51 | } |
| 52 | bool isValueVisibility() const { |
| 53 | return getExplicitVisibilityKind() == NamedDecl::VisibilityForValue; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | static LVComputationKind forLinkageOnly() { |
| 58 | LVComputationKind Result(NamedDecl::VisibilityForValue); |
| 59 | Result.IgnoreExplicitVisibility = true; |
| 60 | Result.IgnoreAllVisibility = true; |
| 61 | return Result; |
| 62 | } |
| 63 | |
| 64 | unsigned toBits() { |
| 65 | unsigned Bits = 0; |
| 66 | Bits = (Bits << 1) | ExplicitKind; |
| 67 | Bits = (Bits << 1) | IgnoreExplicitVisibility; |
| 68 | Bits = (Bits << 1) | IgnoreAllVisibility; |
| 69 | return Bits; |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | class LinkageComputer { |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | using QueryType = |
| 85 | llvm::PointerIntPair<const NamedDecl *, |
| 86 | LVComputationKind::NumLVComputationKindBits>; |
| 87 | llvm::SmallDenseMap<QueryType, LinkageInfo, 8> CachedLinkageInfo; |
| 88 | |
| 89 | static QueryType makeCacheKey(const NamedDecl *ND, LVComputationKind Kind) { |
| 90 | return QueryType(ND, Kind.toBits()); |
| 91 | } |
| 92 | |
| 93 | llvm::Optional<LinkageInfo> lookup(const NamedDecl *ND, |
| 94 | LVComputationKind Kind) const { |
| 95 | auto Iter = CachedLinkageInfo.find(makeCacheKey(ND, Kind)); |
| 96 | if (Iter == CachedLinkageInfo.end()) |
| 97 | return None; |
| 98 | return Iter->second; |
| 99 | } |
| 100 | |
| 101 | void cache(const NamedDecl *ND, LVComputationKind Kind, LinkageInfo Info) { |
| 102 | CachedLinkageInfo[makeCacheKey(ND, Kind)] = Info; |
| 103 | } |
| 104 | |
| 105 | LinkageInfo getLVForTemplateArgumentList(ArrayRef<TemplateArgument> Args, |
| 106 | LVComputationKind computation); |
| 107 | |
| 108 | LinkageInfo getLVForTemplateArgumentList(const TemplateArgumentList &TArgs, |
| 109 | LVComputationKind computation); |
| 110 | |
| 111 | void mergeTemplateLV(LinkageInfo &LV, const FunctionDecl *fn, |
| 112 | const FunctionTemplateSpecializationInfo *specInfo, |
| 113 | LVComputationKind computation); |
| 114 | |
| 115 | void mergeTemplateLV(LinkageInfo &LV, |
| 116 | const ClassTemplateSpecializationDecl *spec, |
| 117 | LVComputationKind computation); |
| 118 | |
| 119 | void mergeTemplateLV(LinkageInfo &LV, |
| 120 | const VarTemplateSpecializationDecl *spec, |
| 121 | LVComputationKind computation); |
| 122 | |
| 123 | LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D, |
| 124 | LVComputationKind computation, |
| 125 | bool IgnoreVarTypeLinkage); |
| 126 | |
| 127 | LinkageInfo getLVForClassMember(const NamedDecl *D, |
| 128 | LVComputationKind computation, |
| 129 | bool IgnoreVarTypeLinkage); |
| 130 | |
| 131 | LinkageInfo getLVForClosure(const DeclContext *DC, Decl *ContextDecl, |
| 132 | LVComputationKind computation); |
| 133 | |
| 134 | LinkageInfo getLVForLocalDecl(const NamedDecl *D, |
| 135 | LVComputationKind computation); |
| 136 | |
| 137 | LinkageInfo getLVForType(const Type &T, LVComputationKind computation); |
| 138 | |
| 139 | LinkageInfo getLVForTemplateParameterList(const TemplateParameterList *Params, |
| 140 | LVComputationKind computation); |
| 141 | |
| 142 | public: |
| 143 | LinkageInfo computeLVForDecl(const NamedDecl *D, |
| 144 | LVComputationKind computation, |
| 145 | bool IgnoreVarTypeLinkage = false); |
| 146 | |
| 147 | LinkageInfo getLVForDecl(const NamedDecl *D, LVComputationKind computation); |
| 148 | |
| 149 | LinkageInfo computeTypeLinkageInfo(const Type *T); |
| 150 | LinkageInfo computeTypeLinkageInfo(QualType T) { |
| 151 | return computeTypeLinkageInfo(T.getTypePtr()); |
| 152 | } |
| 153 | |
| 154 | LinkageInfo getDeclLinkageAndVisibility(const NamedDecl *D); |
| 155 | |
| 156 | LinkageInfo getTypeLinkageAndVisibility(const Type *T); |
| 157 | LinkageInfo getTypeLinkageAndVisibility(QualType T) { |
| 158 | return getTypeLinkageAndVisibility(T.getTypePtr()); |
| 159 | } |
| 160 | }; |
| 161 | } |
| 162 | |
| 163 | #endif |
| 164 | |