]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/Linkage.h
Update clang to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Basic / Linkage.h
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).
33   InternalLinkage,
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.
42   UniqueExternalLinkage,
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.
46   VisibleNoLinkage,
47
48   /// \brief External linkage, which indicates that the entity can
49   /// be referred to from other translation units.
50   ExternalLinkage
51 };
52
53 /// \brief Describes the different kinds of language linkage
54 /// (C++ [dcl.link]) that an entity may have.
55 enum LanguageLinkage {
56   CLanguageLinkage,
57   CXXLanguageLinkage,
58   NoLanguageLinkage
59 };
60
61 /// \brief A more specific kind of linkage than enum Linkage.
62 ///
63 /// This is relevant to CodeGen and AST file reading.
64 enum GVALinkage {
65   GVA_Internal,
66   GVA_AvailableExternally,
67   GVA_DiscardableODR,
68   GVA_StrongExternal,
69   GVA_StrongODR
70 };
71
72 inline bool isDiscardableGVALinkage(GVALinkage L) {
73   return L <= GVA_DiscardableODR;
74 }
75
76 inline bool isExternallyVisible(Linkage L) {
77   return L == ExternalLinkage || L == VisibleNoLinkage;
78 }
79
80 inline Linkage getFormalLinkage(Linkage L) {
81   if (L == UniqueExternalLinkage)
82     return ExternalLinkage;
83   if (L == VisibleNoLinkage)
84     return NoLinkage;
85   return L;
86 }
87
88 inline bool isExternalFormalLinkage(Linkage L) {
89   return getFormalLinkage(L) == ExternalLinkage;
90 }
91
92 /// \brief Compute the minimum linkage given two linkages.
93 ///
94 /// The linkage can be interpreted as a pair formed by the formal linkage and
95 /// a boolean for external visibility. This is just what getFormalLinkage and
96 /// isExternallyVisible return. We want the minimum of both components. The
97 /// Linkage enum is defined in an order that makes this simple, we just need
98 /// special cases for when VisibleNoLinkage would lose the visible bit and
99 /// become NoLinkage.
100 inline Linkage minLinkage(Linkage L1, Linkage L2) {
101   if (L2 == VisibleNoLinkage)
102     std::swap(L1, L2);
103   if (L1 == VisibleNoLinkage) {
104     if (L2 == InternalLinkage)
105       return NoLinkage;
106     if (L2 == UniqueExternalLinkage)
107       return NoLinkage;
108   }
109   return L1 < L2 ? L1 : L2;
110 }
111
112 } // end namespace clang
113
114 #endif // LLVM_CLANG_BASIC_LINKAGE_H