clang  7.0.0svn
Linkage.h
Go to the documentation of this file.
1 //===- Linkage.h - Linkage enumeration and 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 /// \file
11 /// \brief Defines the Linkage enumeration and various utility functions.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_BASIC_LINKAGE_H
16 #define LLVM_CLANG_BASIC_LINKAGE_H
17 
18 #include <utility>
19 
20 namespace clang {
21 
22 /// \brief Describes the different kinds of linkage
23 /// (C++ [basic.link], C99 6.2.2) that an entity may have.
24 enum Linkage : unsigned char {
25  /// \brief No linkage, which means that the entity is unique and
26  /// can only be referred to from within its scope.
27  NoLinkage = 0,
28 
29  /// \brief Internal linkage, which indicates that the entity can
30  /// be referred to from within the translation unit (but not other
31  /// translation units).
33 
34  /// \brief External linkage within a unique namespace.
35  ///
36  /// From the language perspective, these entities have external
37  /// linkage. However, since they reside in an anonymous namespace,
38  /// their names are unique to this translation unit, which is
39  /// equivalent to having internal linkage from the code-generation
40  /// point of view.
42 
43  /// \brief No linkage according to the standard, but is visible from other
44  /// translation units because of types defined in a inline function.
46 
47  /// \brief Internal linkage according to the Modules TS, but can be referred
48  /// to from other translation units indirectly through inline functions and
49  /// templates in the module interface.
51 
52  /// \brief Module linkage, which indicates that the entity can be referred
53  /// to from other translation units within the same module, and indirectly
54  /// from arbitrary other translation units through inline functions and
55  /// templates in the module interface.
57 
58  /// \brief External linkage, which indicates that the entity can
59  /// be referred to from other translation units.
61 };
62 
63 /// \brief Describes the different kinds of language linkage
64 /// (C++ [dcl.link]) that an entity may have.
69 };
70 
71 /// \brief A more specific kind of linkage than enum Linkage.
72 ///
73 /// This is relevant to CodeGen and AST file reading.
74 enum GVALinkage {
80 };
81 
83  return L <= GVA_DiscardableODR;
84 }
85 
86 inline bool isExternallyVisible(Linkage L) {
87  return L >= VisibleNoLinkage;
88 }
89 
91  switch (L) {
93  return ExternalLinkage;
94  case VisibleNoLinkage:
95  return NoLinkage;
97  return InternalLinkage;
98  default:
99  return L;
100  }
101 }
102 
104  return getFormalLinkage(L) == ExternalLinkage;
105 }
106 
107 /// \brief Compute the minimum linkage given two linkages.
108 ///
109 /// The linkage can be interpreted as a pair formed by the formal linkage and
110 /// a boolean for external visibility. This is just what getFormalLinkage and
111 /// isExternallyVisible return. We want the minimum of both components. The
112 /// Linkage enum is defined in an order that makes this simple, we just need
113 /// special cases for when VisibleNoLinkage would lose the visible bit and
114 /// become NoLinkage.
116  if (L2 == VisibleNoLinkage)
117  std::swap(L1, L2);
118  if (L1 == VisibleNoLinkage) {
119  if (L2 == InternalLinkage)
120  return NoLinkage;
121  if (L2 == UniqueExternalLinkage)
122  return NoLinkage;
123  }
124  return L1 < L2 ? L1 : L2;
125 }
126 
127 } // namespace clang
128 
129 #endif // LLVM_CLANG_BASIC_LINKAGE_H
External linkage, which indicates that the entity can be referred to from other translation units...
Definition: Linkage.h:60
Internal linkage according to the Modules TS, but can be referred to from other translation units ind...
Definition: Linkage.h:50
No linkage, which means that the entity is unique and can only be referred to from within its scope...
Definition: Linkage.h:27
bool isDiscardableGVALinkage(GVALinkage L)
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:24
Linkage getFormalLinkage(Linkage L)
Definition: Linkage.h:90
bool isExternalFormalLinkage(Linkage L)
Definition: Linkage.h:103
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition: Linkage.h:56
bool isExternallyVisible(Linkage L)
Definition: Linkage.h:86
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have...
Definition: Linkage.h:65
Linkage minLinkage(Linkage L1, Linkage L2)
Compute the minimum linkage given two linkages.
Definition: Linkage.h:115
Dataflow Directional Tag Classes.
External linkage within a unique namespace.
Definition: Linkage.h:41
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:32
No linkage according to the standard, but is visible from other translation units because of types de...
Definition: Linkage.h:45
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition: Linkage.h:74