]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/clang/include/clang/Basic/Linkage.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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 namespace clang {
18
19 /// \brief Describes the different kinds of linkage 
20 /// (C++ [basic.link], C99 6.2.2) that an entity may have.
21 enum Linkage {
22   /// \brief No linkage, which means that the entity is unique and
23   /// can only be referred to from within its scope.
24   NoLinkage = 0,
25
26   /// \brief Internal linkage, which indicates that the entity can
27   /// be referred to from within the translation unit (but not other
28   /// translation units).
29   InternalLinkage,
30
31   /// \brief External linkage within a unique namespace. 
32   ///
33   /// From the language perspective, these entities have external
34   /// linkage. However, since they reside in an anonymous namespace,
35   /// their names are unique to this translation unit, which is
36   /// equivalent to having internal linkage from the code-generation
37   /// point of view.
38   UniqueExternalLinkage,
39
40   /// \brief No linkage according to the standard, but is visible from other
41   /// translation units because of types defined in a inline function.
42   VisibleNoLinkage,
43
44   /// \brief External linkage, which indicates that the entity can
45   /// be referred to from other translation units.
46   ExternalLinkage
47 };
48
49 /// \brief Describes the different kinds of language linkage
50 /// (C++ [dcl.link]) that an entity may have.
51 enum LanguageLinkage {
52   CLanguageLinkage,
53   CXXLanguageLinkage,
54   NoLanguageLinkage
55 };
56
57 /// \brief A more specific kind of linkage than enum Linkage.
58 ///
59 /// This is relevant to CodeGen and AST file reading.
60 enum GVALinkage {
61   GVA_Internal,
62   GVA_C99Inline,
63   GVA_CXXInline,
64   GVA_StrongExternal,
65   GVA_TemplateInstantiation,
66   GVA_ExplicitTemplateInstantiation
67 };
68
69 inline bool isExternallyVisible(Linkage L) {
70   return L == ExternalLinkage || L == VisibleNoLinkage;
71 }
72
73 inline Linkage getFormalLinkage(Linkage L) {
74   if (L == UniqueExternalLinkage)
75     return ExternalLinkage;
76   if (L == VisibleNoLinkage)
77     return NoLinkage;
78   return L;
79 }
80
81 inline bool isExternalFormalLinkage(Linkage L) {
82   return getFormalLinkage(L) == ExternalLinkage;
83 }
84
85 /// \brief Compute the minimum linkage given two linkages.
86 ///
87 /// The linkage can be interpreted as a pair formed by the formal linkage and
88 /// a boolean for external visibility. This is just what getFormalLinkage and
89 /// isExternallyVisible return. We want the minimum of both components. The
90 /// Linkage enum is defined in an order that makes this simple, we just need
91 /// special cases for when VisibleNoLinkage would lose the visible bit and
92 /// become NoLinkage.
93 inline Linkage minLinkage(Linkage L1, Linkage L2) {
94   if (L2 == VisibleNoLinkage)
95     std::swap(L1, L2);
96   if (L1 == VisibleNoLinkage) {
97     if (L2 == InternalLinkage)
98       return NoLinkage;
99     if (L2 == UniqueExternalLinkage)
100       return NoLinkage;
101   }
102   return L1 < L2 ? L1 : L2;
103 }
104
105 } // end namespace clang
106
107 #endif // LLVM_CLANG_BASIC_LINKAGE_H