Skip to content

Commit f6f086f

Browse files
author
David Ungar
committed
Add Decl::isPrivateToEnclosingFile
1 parent b58ea4b commit f6f086f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,9 @@ class alignas(1 << DeclAlignInBits) Decl {
920920
/// If this returns true, the decl can be safely casted to ValueDecl.
921921
bool isPotentiallyOverridable() const;
922922

923+
/// Returns true if this Decl cannot be seen by any other source file
924+
bool isPrivateToEnclosingFile() const;
925+
923926
/// If an alternative module name is specified for this decl, e.g. using
924927
/// @_originalDefinedIn attribute, this function returns this module name.
925928
StringRef getAlternateModuleName() const;

lib/AST/Decl.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8068,3 +8068,26 @@ void swift::simple_display(llvm::raw_ostream &out, AnyFunctionRef fn) {
80688068
else
80698069
out << "closure";
80708070
}
8071+
8072+
bool Decl::isPrivateToEnclosingFile() const {
8073+
if (auto *VD = dyn_cast<ValueDecl>(this))
8074+
return VD->getFormalAccess() <= AccessLevel::FilePrivate;
8075+
switch (getKind()) {
8076+
case DeclKind::Import:
8077+
case DeclKind::PatternBinding:
8078+
case DeclKind::EnumCase:
8079+
case DeclKind::TopLevelCode:
8080+
case DeclKind::IfConfig:
8081+
case DeclKind::PoundDiagnostic:
8082+
return true;
8083+
8084+
case DeclKind::Extension:
8085+
case DeclKind::InfixOperator:
8086+
case DeclKind::PrefixOperator:
8087+
case DeclKind::PostfixOperator:
8088+
return false;
8089+
8090+
default:
8091+
llvm_unreachable("everything else is a ValueDecl");
8092+
}
8093+
}

0 commit comments

Comments
 (0)