[NFC] [Modules] Introduce 'DeclBase::isInNamedModule' interface

This patch introduces DeclBase::isInNamedModule API to ease the use
of modules slightly.
This commit is contained in:
Chuanqi Xu 2024-07-12 13:32:40 +08:00
parent 870eee464b
commit d384267ad0
4 changed files with 10 additions and 10 deletions

View File

@ -673,6 +673,9 @@ public:
/// Whether this declaration comes from explicit global module.
bool isFromExplicitGlobalModule() const;
/// Whether this declaration comes from a named module.
bool isInNamedModule() const;
/// Return true if this declaration has an attribute which acts as
/// definition of the entity, such as 'alias' or 'ifunc'.
bool hasDefiningAttr() const;

View File

@ -1181,13 +1181,6 @@ Linkage NamedDecl::getLinkageInternal() const {
.getLinkage();
}
/// Determine whether D is attached to a named module.
static bool isInNamedModule(const NamedDecl *D) {
if (auto *M = D->getOwningModule())
return M->isNamedModule();
return false;
}
static bool isExportedFromModuleInterfaceUnit(const NamedDecl *D) {
// FIXME: Handle isModulePrivate.
switch (D->getModuleOwnershipKind()) {
@ -1197,7 +1190,7 @@ static bool isExportedFromModuleInterfaceUnit(const NamedDecl *D) {
return false;
case Decl::ModuleOwnershipKind::Visible:
case Decl::ModuleOwnershipKind::VisibleWhenImported:
return isInNamedModule(D);
return D->isInNamedModule();
}
llvm_unreachable("unexpected module ownership kind");
}
@ -1215,7 +1208,7 @@ Linkage NamedDecl::getFormalLinkage() const {
// [basic.namespace.general]/p2
// A namespace is never attached to a named module and never has a name with
// module linkage.
if (isInNamedModule(this) && InternalLinkage == Linkage::External &&
if (isInNamedModule() && InternalLinkage == Linkage::External &&
!isExportedFromModuleInterfaceUnit(
cast<NamedDecl>(this->getCanonicalDecl())) &&
!isa<NamespaceDecl>(this))

View File

@ -1145,6 +1145,10 @@ bool Decl::isFromExplicitGlobalModule() const {
return getOwningModule() && getOwningModule()->isExplicitGlobalModule();
}
bool Decl::isInNamedModule() const {
return getOwningModule() && getOwningModule()->isNamedModule();
}
static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); }

View File

@ -10094,7 +10094,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
// check at the end of the TU (or when the PMF starts) to see that we
// have a definition at that point.
if (isInline && !D.isFunctionDefinition() && getLangOpts().CPlusPlus20 &&
NewFD->hasOwningModule() && NewFD->getOwningModule()->isNamedModule()) {
NewFD->isInNamedModule()) {
PendingInlineFuncDecls.insert(NewFD);
}
}