Change Type::getLinkageAndVisibility to return a LinkageInfo.

llvm-svn: 176157
This commit is contained in:
Rafael Espindola 2013-02-27 02:27:19 +00:00
parent 9b47f6414b
commit 6fbfafeddc
3 changed files with 17 additions and 27 deletions

View File

@ -1775,13 +1775,17 @@ public:
Linkage getLinkage() const;
/// \brief Determine the visibility of this type.
Visibility getVisibility() const;
Visibility getVisibility() const {
return getLinkageAndVisibility().visibility();
}
/// \brief Return true if the visibility was explicitly set is the code.
bool isVisibilityExplicit() const;
bool isVisibilityExplicit() const {
return getLinkageAndVisibility().visibilityExplicit();
}
/// \brief Determine the linkage and visibility of this type.
std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
LinkageInfo getLinkageAndVisibility() const;
/// \brief Note that the linkage is no longer known.
void ClearLinkageCache();

View File

@ -211,11 +211,6 @@ static Optional<Visibility> getVisibilityOf(const NamedDecl *D,
return None;
}
static LinkageInfo getLVForType(QualType T) {
std::pair<Linkage,Visibility> P = T->getLinkageAndVisibility();
return LinkageInfo(P.first, P.second, T->isVisibilityExplicit());
}
/// \brief Get the most restrictive linkage for the types in the given
/// template parameter list. For visibility purposes, template
/// parameters are part of the signature of a template.
@ -239,7 +234,7 @@ getLVForTemplateParameterList(const TemplateParameterList *params) {
// Handle the non-pack case first.
if (!NTTP->isExpandedParameterPack()) {
if (!NTTP->getType()->isDependentType()) {
LV.merge(getLVForType(NTTP->getType()));
LV.merge(NTTP->getType()->getLinkageAndVisibility());
}
continue;
}
@ -248,7 +243,7 @@ getLVForTemplateParameterList(const TemplateParameterList *params) {
for (unsigned i = 0, n = NTTP->getNumExpansionTypes(); i != n; ++i) {
QualType type = NTTP->getExpansionType(i);
if (!type->isDependentType())
LV.merge(getLVForType(type));
LV.merge(type->getLinkageAndVisibility());
}
continue;
}
@ -296,7 +291,7 @@ getLVForTemplateArgumentList(ArrayRef<TemplateArgument> args) {
continue;
case TemplateArgument::Type:
LV.merge(getLVForType(arg.getAsType()));
LV.merge(arg.getAsType()->getLinkageAndVisibility());
continue;
case TemplateArgument::Declaration:
@ -307,7 +302,7 @@ getLVForTemplateArgumentList(ArrayRef<TemplateArgument> args) {
continue;
case TemplateArgument::NullPtr:
LV.merge(getLVForType(arg.getNullPtrType()));
LV.merge(arg.getNullPtrType()->getLinkageAndVisibility());
continue;
case TemplateArgument::Template:
@ -627,7 +622,7 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D,
// because of this, but unique-external linkage suits us.
if (Context.getLangOpts().CPlusPlus &&
!Var->getDeclContext()->isExternCContext()) {
LinkageInfo TypeLV = getLVForType(Var->getType());
LinkageInfo TypeLV = Var->getType()->getLinkageAndVisibility();
if (TypeLV.linkage() != ExternalLinkage)
return LinkageInfo::uniqueExternal();
if (!LV.visibilityExplicit())
@ -819,7 +814,7 @@ static LinkageInfo getLVForClassMember(const NamedDecl *D,
} else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
// Modify the variable's linkage by its type, but ignore the
// type's visibility unless it's a definition.
LinkageInfo typeLV = getLVForType(VD->getType());
LinkageInfo typeLV = VD->getType()->getLinkageAndVisibility();
LV.mergeMaybeWithVisibility(typeLV,
!LV.visibilityExplicit() && !classLV.visibilityExplicit());

View File

@ -2170,25 +2170,16 @@ Linkage Type::getLinkage() const {
return TypeBits.getLinkage();
}
/// \brief Determine the linkage of this type.
Visibility Type::getVisibility() const {
Cache::ensure(this);
return TypeBits.getVisibility();
}
bool Type::isVisibilityExplicit() const {
Cache::ensure(this);
return TypeBits.isVisibilityExplicit();
}
bool Type::hasUnnamedOrLocalType() const {
Cache::ensure(this);
return TypeBits.hasLocalOrUnnamedType();
}
std::pair<Linkage,Visibility> Type::getLinkageAndVisibility() const {
LinkageInfo Type::getLinkageAndVisibility() const {
Cache::ensure(this);
return std::make_pair(TypeBits.getLinkage(), TypeBits.getVisibility());
LinkageInfo LV(TypeBits.getLinkage(), TypeBits.getVisibility(),
TypeBits.isVisibilityExplicit());
return LV;
}
void Type::ClearLinkageCache() {