George Burgess IV | 99db3ea | 2017-08-09 04:02:49 +0000 | [diff] [blame^] | 1 | //===----- Linkage.h - Linkage calculation-related 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 | // This file provides AST-internal utilities for linkage and visibility |
| 11 | // calculation. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_CLANG_LIB_AST_LINKAGE_H |
| 16 | #define LLVM_CLANG_LIB_AST_LINKAGE_H |
| 17 | |
| 18 | #include "clang/AST/Decl.h" |
| 19 | #include "clang/AST/DeclCXX.h" |
| 20 | #include "clang/AST/Type.h" |
| 21 | #include "llvm/ADT/DenseMap.h" |
| 22 | |
| 23 | namespace clang { |
| 24 | enum : unsigned { |
| 25 | IgnoreExplicitVisibilityBit = 2, |
| 26 | IgnoreAllVisibilityBit = 4 |
| 27 | }; |
| 28 | |
| 29 | /// Kinds of LV computation. The linkage side of the computation is |
| 30 | /// always the same, but different things can change how visibility is |
| 31 | /// computed. |
| 32 | enum LVComputationKind { |
| 33 | /// Do an LV computation for, ultimately, a type. |
| 34 | /// Visibility may be restricted by type visibility settings and |
| 35 | /// the visibility of template arguments. |
| 36 | LVForType = NamedDecl::VisibilityForType, |
| 37 | |
| 38 | /// Do an LV computation for, ultimately, a non-type declaration. |
| 39 | /// Visibility may be restricted by value visibility settings and |
| 40 | /// the visibility of template arguments. |
| 41 | LVForValue = NamedDecl::VisibilityForValue, |
| 42 | |
| 43 | /// Do an LV computation for, ultimately, a type that already has |
| 44 | /// some sort of explicit visibility. Visibility may only be |
| 45 | /// restricted by the visibility of template arguments. |
| 46 | LVForExplicitType = (LVForType | IgnoreExplicitVisibilityBit), |
| 47 | |
| 48 | /// Do an LV computation for, ultimately, a non-type declaration |
| 49 | /// that already has some sort of explicit visibility. Visibility |
| 50 | /// may only be restricted by the visibility of template arguments. |
| 51 | LVForExplicitValue = (LVForValue | IgnoreExplicitVisibilityBit), |
| 52 | |
| 53 | /// Do an LV computation when we only care about the linkage. |
| 54 | LVForLinkageOnly = |
| 55 | LVForValue | IgnoreExplicitVisibilityBit | IgnoreAllVisibilityBit |
| 56 | }; |
| 57 | |
| 58 | class LinkageComputer { |
| 59 | LinkageInfo getLVForTemplateArgumentList(ArrayRef<TemplateArgument> Args, |
| 60 | LVComputationKind computation); |
| 61 | |
| 62 | LinkageInfo getLVForTemplateArgumentList(const TemplateArgumentList &TArgs, |
| 63 | LVComputationKind computation); |
| 64 | |
| 65 | void mergeTemplateLV(LinkageInfo &LV, const FunctionDecl *fn, |
| 66 | const FunctionTemplateSpecializationInfo *specInfo, |
| 67 | LVComputationKind computation); |
| 68 | |
| 69 | void mergeTemplateLV(LinkageInfo &LV, |
| 70 | const ClassTemplateSpecializationDecl *spec, |
| 71 | LVComputationKind computation); |
| 72 | |
| 73 | void mergeTemplateLV(LinkageInfo &LV, |
| 74 | const VarTemplateSpecializationDecl *spec, |
| 75 | LVComputationKind computation); |
| 76 | |
| 77 | LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D, |
| 78 | LVComputationKind computation); |
| 79 | |
| 80 | LinkageInfo getLVForClassMember(const NamedDecl *D, |
| 81 | LVComputationKind computation); |
| 82 | |
| 83 | LinkageInfo getLVForClosure(const DeclContext *DC, Decl *ContextDecl, |
| 84 | LVComputationKind computation); |
| 85 | |
| 86 | LinkageInfo getLVForLocalDecl(const NamedDecl *D, |
| 87 | LVComputationKind computation); |
| 88 | |
| 89 | LinkageInfo getLVForType(const Type &T, LVComputationKind computation); |
| 90 | |
| 91 | LinkageInfo getLVForTemplateParameterList(const TemplateParameterList *Params, |
| 92 | LVComputationKind computation); |
| 93 | |
| 94 | public: |
| 95 | LinkageInfo computeLVForDecl(const NamedDecl *D, |
| 96 | LVComputationKind computation); |
| 97 | |
| 98 | LinkageInfo getLVForDecl(const NamedDecl *D, LVComputationKind computation); |
| 99 | |
| 100 | LinkageInfo computeTypeLinkageInfo(const Type *T); |
| 101 | LinkageInfo computeTypeLinkageInfo(QualType T) { |
| 102 | return computeTypeLinkageInfo(T.getTypePtr()); |
| 103 | } |
| 104 | |
| 105 | LinkageInfo getDeclLinkageAndVisibility(const NamedDecl *D); |
| 106 | |
| 107 | LinkageInfo getTypeLinkageAndVisibility(const Type *T); |
| 108 | LinkageInfo getTypeLinkageAndVisibility(QualType T) { |
| 109 | return getTypeLinkageAndVisibility(T.getTypePtr()); |
| 110 | } |
| 111 | }; |
| 112 | } // namespace clang |
| 113 | |
| 114 | #endif |