"Enum truncated!");
}
- bool operator==(const LinkageInfo &Other) {
- return linkage_ == Other.linkage_ &&
- visibility_ == Other.visibility_ &&
- explicit_ == Other.explicit_;
- }
-
static LinkageInfo external() {
return LinkageInfo();
}
/// \brief Clear the linkage cache in response to a change
/// to the declaration.
- void ClearLVCache();
+ void ClearLinkageCache();
/// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for
/// the underlying named decl.
// First one will point to this one as latest.
First->RedeclLink = LatestDeclLink(static_cast<decl_type*>(this));
if (NamedDecl *ND = dyn_cast<NamedDecl>(static_cast<decl_type*>(this)))
- ND->ClearLVCache();
+ ND->ClearLinkageCache();
}
// Inline function definitions.
SourceLocation Loc;
/// DeclKind - This indicates which class this is.
- unsigned DeclKind : 6;
+ unsigned DeclKind : 8;
/// InvalidDecl - This indicates a semantic error occurred.
unsigned InvalidDecl : 1;
/// IdentifierNamespace - This specifies what IDNS_* namespace this lives in.
unsigned IdentifierNamespace : 12;
- /// These fields are only valid for NamedDecls subclasses.
+ /// \brief Whether the \c CachedLinkage field is active.
+ ///
+ /// This field is only valid for NamedDecls subclasses.
+ mutable unsigned HasCachedLinkage : 1;
+
+ /// \brief If \c HasCachedLinkage, the linkage of this declaration.
///
- /// \brief Nonzero if the cache (i.e. the bitfields here starting
- /// with 'Cache') is valid. If so, then this is a
- /// LangOptions::VisibilityMode+1.
- mutable unsigned CacheValidAndVisibility : 2;
- /// \brief the linkage of this declaration.
+ /// This field is only valid for NamedDecls subclasses.
mutable unsigned CachedLinkage : 2;
- /// \brief true if the visibility is explicit.
- mutable unsigned CachedVisibilityExplicit : 1;
friend class ASTDeclWriter;
friend class ASTDeclReader;
HasAttrs(false), Implicit(false), Used(false), Referenced(false),
Access(AS_none), FromASTFile(0), Hidden(0),
IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
- CacheValidAndVisibility(0)
+ HasCachedLinkage(0)
{
if (StatisticsEnabled) add(DK);
}
HasAttrs(false), Implicit(false), Used(false), Referenced(false),
Access(AS_none), FromASTFile(0), Hidden(0),
IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
- CacheValidAndVisibility(0)
+ HasCachedLinkage(0)
{
if (StatisticsEnabled) add(DK);
}
std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
/// \brief Note that the linkage is no longer known.
- void ClearLVCache();
+ void ClearLinkageCache();
const char *getTypeClassName() const;
return LV;
}
-/// Compute the linkage and visibility for the given declaration.
-static LinkageInfo computeLVForDecl(const NamedDecl *D, bool OnlyTemplate);
-
-static LinkageInfo getLVForDecl(const NamedDecl *D, bool OnlyTemplate) {
- if (!OnlyTemplate)
- return D->getLinkageAndVisibility();
- return computeLVForDecl(D, OnlyTemplate);
-}
+/// getLVForDecl - Get the linkage and visibility for the given declaration.
+static LinkageInfo getLVForDecl(const NamedDecl *D, bool OnlyTemplate);
/// \brief Get the most restrictive linkage for the types and
/// declarations in the given template argument list.
i = record->decls_begin(), e = record->decls_end(); i != e; ++i) {
Decl *child = *i;
if (isa<NamedDecl>(child))
- cast<NamedDecl>(child)->ClearLVCache();
+ cast<NamedDecl>(child)->ClearLinkageCache();
}
}
void NamedDecl::anchor() { }
-void NamedDecl::ClearLVCache() {
+void NamedDecl::ClearLinkageCache() {
// Note that we can't skip clearing the linkage of children just
// because the parent doesn't have cached linkage: we don't cache
// when computing linkage for parent contexts.
- CacheValidAndVisibility = 0;
+ HasCachedLinkage = 0;
// If we're changing the linkage of a class, we need to reset the
// linkage of child declarations, too.
dyn_cast<ClassTemplateDecl>(const_cast<NamedDecl*>(this))) {
// Clear linkage for the template pattern.
CXXRecordDecl *record = temp->getTemplatedDecl();
- record->CacheValidAndVisibility = 0;
+ record->HasCachedLinkage = 0;
clearLinkageForClass(record);
// We need to clear linkage for specializations, too.
for (ClassTemplateDecl::spec_iterator
i = temp->spec_begin(), e = temp->spec_end(); i != e; ++i)
- i->ClearLVCache();
+ i->ClearLinkageCache();
}
// Clear cached linkage for function template decls, too.
if (FunctionTemplateDecl *temp =
dyn_cast<FunctionTemplateDecl>(const_cast<NamedDecl*>(this))) {
- temp->getTemplatedDecl()->ClearLVCache();
+ temp->getTemplatedDecl()->ClearLinkageCache();
for (FunctionTemplateDecl::spec_iterator
i = temp->spec_begin(), e = temp->spec_end(); i != e; ++i)
- i->ClearLVCache();
+ i->ClearLinkageCache();
}
}
Linkage NamedDecl::getLinkage() const {
- return getLinkageAndVisibility().linkage();
+ if (HasCachedLinkage) {
+ assert(Linkage(CachedLinkage) ==
+ getLVForDecl(this, true).linkage());
+ return Linkage(CachedLinkage);
+ }
+
+ CachedLinkage = getLVForDecl(this, true).linkage();
+ HasCachedLinkage = 1;
+ return Linkage(CachedLinkage);
}
LinkageInfo NamedDecl::getLinkageAndVisibility() const {
- if (CacheValidAndVisibility) {
- Linkage L = static_cast<Linkage>(CachedLinkage);
- Visibility V = static_cast<Visibility>(CacheValidAndVisibility - 1);
- bool Explicit = CachedVisibilityExplicit;
- LinkageInfo LV(L, V, Explicit);
- assert(LV == computeLVForDecl(this, false));
- return LV;
- }
- LinkageInfo LV = computeLVForDecl(this, false);
- CachedLinkage = LV.linkage();
- CacheValidAndVisibility = LV.visibility() + 1;
- CachedVisibilityExplicit = LV.visibilityExplicit();
- return LV;
+ LinkageInfo LI = getLVForDecl(this, false);
+ assert(!HasCachedLinkage || Linkage(CachedLinkage) == LI.linkage());
+ HasCachedLinkage = 1;
+ CachedLinkage = LI.linkage();
+ return LI;
}
llvm::Optional<Visibility> NamedDecl::getExplicitVisibility() const {
return llvm::Optional<Visibility>();
}
-static LinkageInfo computeLVForDecl(const NamedDecl *D, bool OnlyTemplate) {
+static LinkageInfo getLVForDecl(const NamedDecl *D, bool OnlyTemplate) {
// Objective-C: treat all Objective-C declarations as having external
// linkage.
switch (D->getKind()) {
void VarDecl::setStorageClass(StorageClass SC) {
assert(isLegalForVariable(SC));
if (getStorageClass() != SC)
- ClearLVCache();
+ ClearLinkageCache();
VarDeclBits.SClass = SC;
}
Body = B;
if (B)
EndRangeLoc = B->getLocEnd();
- ClearLVCache();
}
void FunctionDecl::setPure(bool P) {
void FunctionDecl::setStorageClass(StorageClass SC) {
assert(isLegalForFunction(SC));
if (getStorageClass() != SC)
- ClearLVCache();
+ ClearLinkageCache();
SClass = SC;
}
void TagDecl::setTypedefNameForAnonDecl(TypedefNameDecl *TDD) {
TypedefNameDeclOrQualifier = TDD;
if (TypeForDecl)
- const_cast<Type*>(TypeForDecl)->ClearLVCache();
- ClearLVCache();
+ const_cast<Type*>(TypeForDecl)->ClearLinkageCache();
+ ClearLinkageCache();
}
void TagDecl::startDefinition() {
return std::make_pair(TypeBits.getLinkage(), TypeBits.getVisibility());
}
-void Type::ClearLVCache() {
+void Type::ClearLinkageCache() {
TypeBits.CacheValidAndVisibility = 0;
if (QualType(this, 0) != CanonicalType)
CanonicalType->TypeBits.CacheValidAndVisibility = 0;
if (!VisContext)
return;
- NamedDecl *ND = dyn_cast<NamedDecl>(D);
- if (ND && ND->getExplicitVisibility())
+ if (isa<NamedDecl>(D) && cast<NamedDecl>(D)->getExplicitVisibility())
return;
VisStack *Stack = static_cast<VisStack*>(VisContext);
= (VisibilityAttr::VisibilityType) rawType;
SourceLocation loc = Stack->back().second;
- ND->ClearLVCache();
D->addAttr(::new (Context) VisibilityAttr(loc, Context, type));
}
AA->getIntroduced(), AA->getDeprecated(),
AA->getObsoleted(), AA->getUnavailable(),
AA->getMessage());
- else if (VisibilityAttr *VA = dyn_cast<VisibilityAttr>(Attr)) {
+ else if (VisibilityAttr *VA = dyn_cast<VisibilityAttr>(Attr))
NewAttr = mergeVisibilityAttr(D, VA->getRange(), VA->getVisibility());
- if (NewAttr) {
- NamedDecl *ND = cast<NamedDecl>(D);
- ND->ClearLVCache();
- }
- } else if (DLLImportAttr *ImportA = dyn_cast<DLLImportAttr>(Attr))
+ else if (DLLImportAttr *ImportA = dyn_cast<DLLImportAttr>(Attr))
NewAttr = mergeDLLImportAttr(D, ImportA->getRange());
else if (DLLExportAttr *ExportA = dyn_cast<DLLExportAttr>(Attr))
NewAttr = mergeDLLExportAttr(D, ExportA->getRange());
}
VDecl->setTypeSourceInfo(DeducedType);
VDecl->setType(DeducedType->getType());
- VDecl->ClearLVCache();
+ VDecl->ClearLinkageCache();
// In ARC, infer lifetime.
if (getLangOpts().ObjCAutoRefCount && inferObjCARCLifetime(VDecl))
Deprecated.Version,
Obsoleted.Version,
IsUnavailable, Str);
- if (NewAttr) {
+ if (NewAttr)
D->addAttr(NewAttr);
- NamedDecl *ND = cast<NamedDecl>(D);
- ND->ClearLVCache();
- }
}
VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, SourceRange Range,
Diag(ExistingAttr->getLocation(), diag::err_mismatched_visibility);
Diag(Range.getBegin(), diag::note_previous_attribute);
D->dropAttr<VisibilityAttr>();
- NamedDecl *ND = cast<NamedDecl>(D);
- ND->ClearLVCache();
}
return ::new (Context) VisibilityAttr(Range, Context, Vis);
}
}
VisibilityAttr *NewAttr = S.mergeVisibilityAttr(D, Attr.getRange(), type);
- if (NewAttr) {
+ if (NewAttr)
D->addAttr(NewAttr);
- NamedDecl *ND = cast<NamedDecl>(D);
- ND->ClearLVCache();
- }
}
static void handleObjCMethodFamilyAttr(Sema &S, Decl *decl,