Skip to content

Commit d384267

Browse files
committed
[NFC] [Modules] Introduce 'DeclBase::isInNamedModule' interface
This patch introduces DeclBase::isInNamedModule API to ease the use of modules slightly.
1 parent 870eee4 commit d384267

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

clang/include/clang/AST/DeclBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,9 @@ class alignas(8) Decl {
673673
/// Whether this declaration comes from explicit global module.
674674
bool isFromExplicitGlobalModule() const;
675675

676+
/// Whether this declaration comes from a named module.
677+
bool isInNamedModule() const;
678+
676679
/// Return true if this declaration has an attribute which acts as
677680
/// definition of the entity, such as 'alias' or 'ifunc'.
678681
bool hasDefiningAttr() const;

clang/lib/AST/Decl.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,13 +1181,6 @@ Linkage NamedDecl::getLinkageInternal() const {
11811181
.getLinkage();
11821182
}
11831183

1184-
/// Determine whether D is attached to a named module.
1185-
static bool isInNamedModule(const NamedDecl *D) {
1186-
if (auto *M = D->getOwningModule())
1187-
return M->isNamedModule();
1188-
return false;
1189-
}
1190-
11911184
static bool isExportedFromModuleInterfaceUnit(const NamedDecl *D) {
11921185
// FIXME: Handle isModulePrivate.
11931186
switch (D->getModuleOwnershipKind()) {
@@ -1197,7 +1190,7 @@ static bool isExportedFromModuleInterfaceUnit(const NamedDecl *D) {
11971190
return false;
11981191
case Decl::ModuleOwnershipKind::Visible:
11991192
case Decl::ModuleOwnershipKind::VisibleWhenImported:
1200-
return isInNamedModule(D);
1193+
return D->isInNamedModule();
12011194
}
12021195
llvm_unreachable("unexpected module ownership kind");
12031196
}
@@ -1215,7 +1208,7 @@ Linkage NamedDecl::getFormalLinkage() const {
12151208
// [basic.namespace.general]/p2
12161209
// A namespace is never attached to a named module and never has a name with
12171210
// module linkage.
1218-
if (isInNamedModule(this) && InternalLinkage == Linkage::External &&
1211+
if (isInNamedModule() && InternalLinkage == Linkage::External &&
12191212
!isExportedFromModuleInterfaceUnit(
12201213
cast<NamedDecl>(this->getCanonicalDecl())) &&
12211214
!isa<NamespaceDecl>(this))

clang/lib/AST/DeclBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,10 @@ bool Decl::isFromExplicitGlobalModule() const {
11451145
return getOwningModule() && getOwningModule()->isExplicitGlobalModule();
11461146
}
11471147

1148+
bool Decl::isInNamedModule() const {
1149+
return getOwningModule() && getOwningModule()->isNamedModule();
1150+
}
1151+
11481152
static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
11491153
static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); }
11501154

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10094,7 +10094,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1009410094
// check at the end of the TU (or when the PMF starts) to see that we
1009510095
// have a definition at that point.
1009610096
if (isInline && !D.isFunctionDefinition() && getLangOpts().CPlusPlus20 &&
10097-
NewFD->hasOwningModule() && NewFD->getOwningModule()->isNamedModule()) {
10097+
NewFD->isInNamedModule()) {
1009810098
PendingInlineFuncDecls.insert(NewFD);
1009910099
}
1010010100
}

0 commit comments

Comments
 (0)