clang 17.0.0git
Linkage.h
Go to the documentation of this file.
1//===- Linkage.h - Linkage enumeration and utilities ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// Defines the Linkage enumeration and various utility functions.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_BASIC_LINKAGE_H
15#define LLVM_CLANG_BASIC_LINKAGE_H
16
17#include <utility>
18
19namespace clang {
20
21/// Describes the different kinds of linkage
22/// (C++ [basic.link], C99 6.2.2) that an entity may have.
23enum Linkage : unsigned char {
24 /// No linkage, which means that the entity is unique and
25 /// can only be referred to from within its scope.
27
28 /// Internal linkage, which indicates that the entity can
29 /// be referred to from within the translation unit (but not other
30 /// translation units).
32
33 /// External linkage within a unique namespace.
34 ///
35 /// From the language perspective, these entities have external
36 /// linkage. However, since they reside in an anonymous namespace,
37 /// their names are unique to this translation unit, which is
38 /// equivalent to having internal linkage from the code-generation
39 /// point of view.
41
42 /// No linkage according to the standard, but is visible from other
43 /// translation units because of types defined in a inline function.
45
46 /// Module linkage, which indicates that the entity can be referred
47 /// to from other translation units within the same module, and indirectly
48 /// from arbitrary other translation units through inline functions and
49 /// templates in the module interface.
51
52 /// External linkage, which indicates that the entity can
53 /// be referred to from other translation units.
55};
56
57/// Describes the different kinds of language linkage
58/// (C++ [dcl.link]) that an entity may have.
63};
64
65/// A more specific kind of linkage than enum Linkage.
66///
67/// This is relevant to CodeGen and AST file reading.
74};
75
77 return L <= GVA_DiscardableODR;
78}
79
80/// Do we know that this will be the only definition of this symbol (excluding
81/// inlining-only definitions)?
83 return L == GVA_Internal || L == GVA_StrongExternal;
84}
85
87 return L >= VisibleNoLinkage;
88}
89
91 switch (L) {
93 return ExternalLinkage;
95 return NoLinkage;
96 default:
97 return L;
98 }
99}
100
103}
104
105/// Compute the minimum linkage given two linkages.
106///
107/// The linkage can be interpreted as a pair formed by the formal linkage and
108/// a boolean for external visibility. This is just what getFormalLinkage and
109/// isExternallyVisible return. We want the minimum of both components. The
110/// Linkage enum is defined in an order that makes this simple, we just need
111/// special cases for when VisibleNoLinkage would lose the visible bit and
112/// become NoLinkage.
114 if (L2 == VisibleNoLinkage)
115 std::swap(L1, L2);
116 if (L1 == VisibleNoLinkage) {
117 if (L2 == InternalLinkage)
118 return NoLinkage;
119 if (L2 == UniqueExternalLinkage)
120 return NoLinkage;
121 }
122 return L1 < L2 ? L1 : L2;
123}
124
125} // namespace clang
126
127#endif // LLVM_CLANG_BASIC_LINKAGE_H
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition: Linkage.h:68
@ GVA_StrongODR
Definition: Linkage.h:73
@ GVA_StrongExternal
Definition: Linkage.h:72
@ GVA_AvailableExternally
Definition: Linkage.h:70
@ GVA_DiscardableODR
Definition: Linkage.h:71
@ GVA_Internal
Definition: Linkage.h:69
Linkage minLinkage(Linkage L1, Linkage L2)
Compute the minimum linkage given two linkages.
Definition: Linkage.h:113
Linkage getFormalLinkage(Linkage L)
Definition: Linkage.h:90
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
Definition: Linkage.h:59
@ CLanguageLinkage
Definition: Linkage.h:60
@ CXXLanguageLinkage
Definition: Linkage.h:61
@ NoLanguageLinkage
Definition: Linkage.h:62
bool isUniqueGVALinkage(GVALinkage L)
Do we know that this will be the only definition of this symbol (excluding inlining-only definitions)...
Definition: Linkage.h:82
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:23
@ InternalLinkage
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:31
@ ModuleLinkage
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition: Linkage.h:50
@ NoLinkage
No linkage, which means that the entity is unique and can only be referred to from within its scope.
Definition: Linkage.h:26
@ ExternalLinkage
External linkage, which indicates that the entity can be referred to from other translation units.
Definition: Linkage.h:54
@ UniqueExternalLinkage
External linkage within a unique namespace.
Definition: Linkage.h:40
@ VisibleNoLinkage
No linkage according to the standard, but is visible from other translation units because of types de...
Definition: Linkage.h:44
bool isDiscardableGVALinkage(GVALinkage L)
Definition: Linkage.h:76
bool isExternalFormalLinkage(Linkage L)
Definition: Linkage.h:101
bool isExternallyVisible(Linkage L)
Definition: Linkage.h:86