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