|
|
|||
File indexing completed on 2026-05-10 08:36:50
0001 //===- Linkage.h - Linkage enumeration and utilities ------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 /// \file 0010 /// Defines the Linkage enumeration and various utility functions. 0011 // 0012 //===----------------------------------------------------------------------===// 0013 0014 #ifndef LLVM_CLANG_BASIC_LINKAGE_H 0015 #define LLVM_CLANG_BASIC_LINKAGE_H 0016 0017 #include "llvm/Support/ErrorHandling.h" 0018 #include <utility> 0019 0020 namespace clang { 0021 0022 /// Describes the different kinds of linkage 0023 /// (C++ [basic.link], C99 6.2.2) that an entity may have. 0024 enum class Linkage : unsigned char { 0025 // Linkage hasn't been computed. 0026 Invalid = 0, 0027 0028 /// No linkage, which means that the entity is unique and 0029 /// can only be referred to from within its scope. 0030 None, 0031 0032 /// Internal linkage, which indicates that the entity can 0033 /// be referred to from within the translation unit (but not other 0034 /// translation units). 0035 Internal, 0036 0037 /// External linkage within a unique namespace. 0038 /// 0039 /// From the language perspective, these entities have external 0040 /// linkage. However, since they reside in an anonymous namespace, 0041 /// their names are unique to this translation unit, which is 0042 /// equivalent to having internal linkage from the code-generation 0043 /// point of view. 0044 UniqueExternal, 0045 0046 /// No linkage according to the standard, but is visible from other 0047 /// translation units because of types defined in a inline function. 0048 VisibleNone, 0049 0050 /// Module linkage, which indicates that the entity can be referred 0051 /// to from other translation units within the same module, and indirectly 0052 /// from arbitrary other translation units through inline functions and 0053 /// templates in the module interface. 0054 Module, 0055 0056 /// External linkage, which indicates that the entity can 0057 /// be referred to from other translation units. 0058 External 0059 }; 0060 0061 /// Describes the different kinds of language linkage 0062 /// (C++ [dcl.link]) that an entity may have. 0063 enum LanguageLinkage { 0064 CLanguageLinkage, 0065 CXXLanguageLinkage, 0066 NoLanguageLinkage 0067 }; 0068 0069 /// A more specific kind of linkage than enum Linkage. 0070 /// 0071 /// This is relevant to CodeGen and AST file reading. 0072 enum GVALinkage { 0073 GVA_Internal, 0074 GVA_AvailableExternally, 0075 GVA_DiscardableODR, 0076 GVA_StrongExternal, 0077 GVA_StrongODR 0078 }; 0079 0080 inline bool isDiscardableGVALinkage(GVALinkage L) { 0081 return L <= GVA_DiscardableODR; 0082 } 0083 0084 /// Do we know that this will be the only definition of this symbol (excluding 0085 /// inlining-only definitions)? 0086 inline bool isUniqueGVALinkage(GVALinkage L) { 0087 return L == GVA_Internal || L == GVA_StrongExternal; 0088 } 0089 0090 inline bool isExternallyVisible(Linkage L) { 0091 switch (L) { 0092 case Linkage::Invalid: 0093 llvm_unreachable("Linkage hasn't been computed!"); 0094 case Linkage::None: 0095 case Linkage::Internal: 0096 case Linkage::UniqueExternal: 0097 return false; 0098 case Linkage::VisibleNone: 0099 case Linkage::Module: 0100 case Linkage::External: 0101 return true; 0102 } 0103 llvm_unreachable("Unhandled Linkage enum"); 0104 } 0105 0106 inline Linkage getFormalLinkage(Linkage L) { 0107 switch (L) { 0108 case Linkage::UniqueExternal: 0109 return Linkage::External; 0110 case Linkage::VisibleNone: 0111 return Linkage::None; 0112 default: 0113 return L; 0114 } 0115 } 0116 0117 inline bool isExternalFormalLinkage(Linkage L) { 0118 return getFormalLinkage(L) == Linkage::External; 0119 } 0120 0121 /// Compute the minimum linkage given two linkages. 0122 /// 0123 /// The linkage can be interpreted as a pair formed by the formal linkage and 0124 /// a boolean for external visibility. This is just what getFormalLinkage and 0125 /// isExternallyVisible return. We want the minimum of both components. The 0126 /// Linkage enum is defined in an order that makes this simple, we just need 0127 /// special cases for when VisibleNoLinkage would lose the visible bit and 0128 /// become NoLinkage. 0129 inline Linkage minLinkage(Linkage L1, Linkage L2) { 0130 if (L2 == Linkage::VisibleNone) 0131 std::swap(L1, L2); 0132 if (L1 == Linkage::VisibleNone) { 0133 if (L2 == Linkage::Internal) 0134 return Linkage::None; 0135 if (L2 == Linkage::UniqueExternal) 0136 return Linkage::None; 0137 } 0138 return L1 < L2 ? L1 : L2; 0139 } 0140 0141 } // namespace clang 0142 0143 #endif // LLVM_CLANG_BASIC_LINKAGE_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|