r176155 - Move LinkageInfo out of NamedDecl so that it can be used in Type.h.
Rafael Espindola
rafael.espindola at gmail.com
Tue Feb 26 18:15:29 PST 2013
Author: rafael
Date: Tue Feb 26 20:15:29 2013
New Revision: 176155
URL: http://llvm.org/viewvc/llvm-project?rev=176155&view=rev
Log:
Move LinkageInfo out of NamedDecl so that it can be used in Type.h.
Everything that cares about visibility also cares about linkage, so I just
moved it to Visibility.h instead of creating a new .h.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Basic/Visibility.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=176155&r1=176154&r2=176155&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Feb 26 20:15:29 2013
@@ -211,81 +211,6 @@ public:
/// a C++ class.
bool isCXXInstanceMember() const;
- class LinkageInfo {
- uint8_t linkage_ : 2;
- uint8_t visibility_ : 2;
- uint8_t explicit_ : 1;
-
- void setVisibility(Visibility V, bool E) { visibility_ = V; explicit_ = E; }
- public:
- LinkageInfo() : linkage_(ExternalLinkage), visibility_(DefaultVisibility),
- explicit_(false) {}
- LinkageInfo(Linkage L, Visibility V, bool E)
- : linkage_(L), visibility_(V), explicit_(E) {
- assert(linkage() == L && visibility() == V && visibilityExplicit() == E &&
- "Enum truncated!");
- }
-
- static LinkageInfo external() {
- return LinkageInfo();
- }
- static LinkageInfo internal() {
- return LinkageInfo(InternalLinkage, DefaultVisibility, false);
- }
- static LinkageInfo uniqueExternal() {
- return LinkageInfo(UniqueExternalLinkage, DefaultVisibility, false);
- }
- static LinkageInfo none() {
- return LinkageInfo(NoLinkage, DefaultVisibility, false);
- }
-
- Linkage linkage() const { return (Linkage)linkage_; }
- Visibility visibility() const { return (Visibility)visibility_; }
- bool visibilityExplicit() const { return explicit_; }
-
- void setLinkage(Linkage L) { linkage_ = L; }
-
- void mergeLinkage(Linkage L) {
- setLinkage(minLinkage(linkage(), L));
- }
- void mergeLinkage(LinkageInfo other) {
- mergeLinkage(other.linkage());
- }
-
- /// Merge in the visibility 'newVis'.
- void mergeVisibility(Visibility newVis, bool newExplicit) {
- Visibility oldVis = visibility();
-
- // Never increase visibility.
- if (oldVis < newVis)
- return;
-
- // If the new visibility is the same as the old and the new
- // visibility isn't explicit, we have nothing to add.
- if (oldVis == newVis && !newExplicit)
- return;
-
- // Otherwise, we're either decreasing visibility or making our
- // existing visibility explicit.
- setVisibility(newVis, newExplicit);
- }
- void mergeVisibility(LinkageInfo other) {
- mergeVisibility(other.visibility(), other.visibilityExplicit());
- }
-
- /// Merge both linkage and visibility.
- void merge(LinkageInfo other) {
- mergeLinkage(other);
- mergeVisibility(other);
- }
-
- /// Merge linkage and conditionally merge visibility.
- void mergeMaybeWithVisibility(LinkageInfo other, bool withVis) {
- mergeLinkage(other);
- if (withVis) mergeVisibility(other);
- }
- };
-
/// \brief Determine what kind of linkage this entity has.
Linkage getLinkage() const;
Modified: cfe/trunk/include/clang/Basic/Visibility.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Visibility.h?rev=176155&r1=176154&r2=176155&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Visibility.h (original)
+++ cfe/trunk/include/clang/Basic/Visibility.h Tue Feb 26 20:15:29 2013
@@ -15,6 +15,8 @@
#ifndef LLVM_CLANG_BASIC_VISIBILITY_H
#define LLVM_CLANG_BASIC_VISIBILITY_H
+#include "clang/Basic/Linkage.h"
+
namespace clang {
/// \brief Describes the different kinds of visibility that a declaration
@@ -46,6 +48,80 @@ inline Visibility minVisibility(Visibili
return L < R ? L : R;
}
+class LinkageInfo {
+ uint8_t linkage_ : 2;
+ uint8_t visibility_ : 2;
+ uint8_t explicit_ : 1;
+
+ void setVisibility(Visibility V, bool E) { visibility_ = V; explicit_ = E; }
+public:
+ LinkageInfo() : linkage_(ExternalLinkage), visibility_(DefaultVisibility),
+ explicit_(false) {}
+ LinkageInfo(Linkage L, Visibility V, bool E)
+ : linkage_(L), visibility_(V), explicit_(E) {
+ assert(linkage() == L && visibility() == V && visibilityExplicit() == E &&
+ "Enum truncated!");
+ }
+
+ static LinkageInfo external() {
+ return LinkageInfo();
+ }
+ static LinkageInfo internal() {
+ return LinkageInfo(InternalLinkage, DefaultVisibility, false);
+ }
+ static LinkageInfo uniqueExternal() {
+ return LinkageInfo(UniqueExternalLinkage, DefaultVisibility, false);
+ }
+ static LinkageInfo none() {
+ return LinkageInfo(NoLinkage, DefaultVisibility, false);
+ }
+
+ Linkage linkage() const { return (Linkage)linkage_; }
+ Visibility visibility() const { return (Visibility)visibility_; }
+ bool visibilityExplicit() const { return explicit_; }
+
+ void setLinkage(Linkage L) { linkage_ = L; }
+
+ void mergeLinkage(Linkage L) {
+ setLinkage(minLinkage(linkage(), L));
+ }
+ void mergeLinkage(LinkageInfo other) {
+ mergeLinkage(other.linkage());
+ }
+
+ /// Merge in the visibility 'newVis'.
+ void mergeVisibility(Visibility newVis, bool newExplicit) {
+ Visibility oldVis = visibility();
+
+ // Never increase visibility.
+ if (oldVis < newVis)
+ return;
+
+ // If the new visibility is the same as the old and the new
+ // visibility isn't explicit, we have nothing to add.
+ if (oldVis == newVis && !newExplicit)
+ return;
+
+ // Otherwise, we're either decreasing visibility or making our
+ // existing visibility explicit.
+ setVisibility(newVis, newExplicit);
+ }
+ void mergeVisibility(LinkageInfo other) {
+ mergeVisibility(other.visibility(), other.visibilityExplicit());
+ }
+
+ /// Merge both linkage and visibility.
+ void merge(LinkageInfo other) {
+ mergeLinkage(other);
+ mergeVisibility(other);
+ }
+
+ /// Merge linkage and conditionally merge visibility.
+ void mergeMaybeWithVisibility(LinkageInfo other, bool withVis) {
+ mergeLinkage(other);
+ if (withVis) mergeVisibility(other);
+ }
+};
}
#endif // LLVM_CLANG_BASIC_VISIBILITY_H
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=176155&r1=176154&r2=176155&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Feb 26 20:15:29 2013
@@ -138,8 +138,6 @@ static Optional<Visibility> getExplicitV
return D->getExplicitVisibility((NamedDecl::ExplicitVisibilityKind) kind);
}
-typedef NamedDecl::LinkageInfo LinkageInfo;
-
/// Is the given declaration a "type" or a "value" for the purposes of
/// visibility computation?
static bool usesTypeVisibility(const NamedDecl *D) {
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=176155&r1=176154&r2=176155&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Feb 26 20:15:29 2013
@@ -2002,20 +2002,19 @@ namespace {
/// \brief The cached properties of a type.
class CachedProperties {
- NamedDecl::LinkageInfo LV;
+ LinkageInfo LV;
bool local;
-
+
public:
- CachedProperties(NamedDecl::LinkageInfo LV, bool local)
- : LV(LV), local(local) {}
-
+ CachedProperties(LinkageInfo LV, bool local) : LV(LV), local(local) {}
+
Linkage getLinkage() const { return LV.linkage(); }
Visibility getVisibility() const { return LV.visibility(); }
bool isVisibilityExplicit() const { return LV.visibilityExplicit(); }
bool hasLocalOrUnnamedType() const { return local; }
-
+
friend CachedProperties merge(CachedProperties L, CachedProperties R) {
- NamedDecl::LinkageInfo MergedLV = L.LV;
+ LinkageInfo MergedLV = L.LV;
MergedLV.merge(R.LV);
return CachedProperties(MergedLV,
L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType());
@@ -2037,9 +2036,9 @@ public:
static CachedProperties get(const Type *T) {
ensure(T);
- NamedDecl::LinkageInfo LV(T->TypeBits.getLinkage(),
- T->TypeBits.getVisibility(),
- T->TypeBits.isVisibilityExplicit());
+ LinkageInfo LV(T->TypeBits.getLinkage(),
+ T->TypeBits.getVisibility(),
+ T->TypeBits.isVisibilityExplicit());
return CachedProperties(LV, T->TypeBits.hasLocalOrUnnamedType());
}
@@ -2092,13 +2091,13 @@ static CachedProperties computeCachedPro
#include "clang/AST/TypeNodes.def"
// Treat instantiation-dependent types as external.
assert(T->isInstantiationDependentType());
- return CachedProperties(NamedDecl::LinkageInfo(), false);
+ return CachedProperties(LinkageInfo(), false);
case Type::Builtin:
// C++ [basic.link]p8:
// A type is said to have linkage if and only if:
// - it is a fundamental type (3.9.1); or
- return CachedProperties(NamedDecl::LinkageInfo(), false);
+ return CachedProperties(LinkageInfo(), false);
case Type::Record:
case Type::Enum: {
@@ -2108,7 +2107,7 @@ static CachedProperties computeCachedPro
// - it is a class or enumeration type that is named (or has a name
// for linkage purposes (7.1.3)) and the name has linkage; or
// - it is a specialization of a class template (14); or
- NamedDecl::LinkageInfo LV = Tag->getLinkageAndVisibility();
+ LinkageInfo LV = Tag->getLinkageAndVisibility();
bool IsLocalOrUnnamed =
Tag->getDeclContext()->isFunctionOrMethod() ||
(!Tag->getIdentifier() && !Tag->getTypedefNameForAnonDecl());
@@ -2150,7 +2149,7 @@ static CachedProperties computeCachedPro
return result;
}
case Type::ObjCInterface: {
- NamedDecl::LinkageInfo LV =
+ LinkageInfo LV =
cast<ObjCInterfaceType>(T)->getDecl()->getLinkageAndVisibility();
return CachedProperties(LV, false);
}
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=176155&r1=176154&r2=176155&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Feb 26 20:15:29 2013
@@ -276,7 +276,7 @@ void CodeGenModule::setGlobalVisibility(
}
// Set visibility for definitions.
- NamedDecl::LinkageInfo LV = D->getLinkageAndVisibility();
+ LinkageInfo LV = D->getLinkageAndVisibility();
if (LV.visibilityExplicit() || !GV->hasAvailableExternallyLinkage())
GV->setVisibility(GetLLVMVisibility(LV.visibility()));
}
@@ -693,7 +693,7 @@ void CodeGenModule::SetFunctionAttribute
} else {
F->setLinkage(llvm::Function::ExternalLinkage);
- NamedDecl::LinkageInfo LV = FD->getLinkageAndVisibility();
+ LinkageInfo LV = FD->getLinkageAndVisibility();
if (LV.linkage() == ExternalLinkage && LV.visibilityExplicit()) {
F->setVisibility(GetLLVMVisibility(LV.visibility()));
}
@@ -1433,7 +1433,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str
GV->setConstant(isTypeConstant(D->getType(), false));
// Set linkage and visibility in case we never see a definition.
- NamedDecl::LinkageInfo LV = D->getLinkageAndVisibility();
+ LinkageInfo LV = D->getLinkageAndVisibility();
if (LV.linkage() != ExternalLinkage) {
// Don't set internal linkage on declarations.
} else {
More information about the cfe-commits
mailing list