@@ -72,40 +72,12 @@ static std::string mangleTypeAsContext(const NominalTypeDecl *NTD) {
72
72
// MARK: Privacy queries
73
73
// ==============================================================================
74
74
75
- static bool declIsPrivate (const ValueDecl *VD) {
76
- return VD->getFormalAccess () <= AccessLevel::FilePrivate;
77
- }
78
-
79
- // / Return true if \param D cannot affect other files.
80
- static bool declIsPrivate (const Decl *D) {
81
- if (auto *VD = dyn_cast<ValueDecl>(D))
82
- return declIsPrivate (VD);
83
- switch (D->getKind ()) {
84
- case DeclKind::Import:
85
- case DeclKind::PatternBinding:
86
- case DeclKind::EnumCase:
87
- case DeclKind::TopLevelCode:
88
- case DeclKind::IfConfig:
89
- case DeclKind::PoundDiagnostic:
90
- return true ;
91
-
92
- case DeclKind::Extension:
93
- case DeclKind::InfixOperator:
94
- case DeclKind::PrefixOperator:
95
- case DeclKind::PostfixOperator:
96
- return false ;
97
-
98
- default :
99
- llvm_unreachable (" everything else is a ValueDecl" );
100
- }
101
- }
102
-
103
75
// / Return true if \ref ED does not contain a member that can affect other
104
76
// / files.
105
77
static bool allMembersArePrivate (const ExtensionDecl *ED) {
106
- return std::all_of (ED-> getMembers (). begin (), ED-> getMembers (). end (),
107
- []( const Decl *d) { return declIsPrivate (d); });
108
- // declIsPrivate );
78
+ return std::all_of (
79
+ ED-> getMembers (). begin (), ED-> getMembers (). end (),
80
+ []( const Decl *d) { return d-> isPrivateToEnclosingFile (); } );
109
81
}
110
82
111
83
// / \ref inheritedType, an inherited protocol, return true if this inheritance
@@ -125,7 +97,7 @@ static bool extendedTypeIsPrivate(TypeLoc inheritedType) {
125
97
" Should not have a subclass existential "
126
98
" in the inheritance clause of an extension" );
127
99
for (auto protoTy : layout.getProtocols ()) {
128
- if (!declIsPrivate ( protoTy->getDecl ()))
100
+ if (!protoTy->getDecl ()-> isPrivateToEnclosingFile ( ))
129
101
return false ;
130
102
}
131
103
@@ -448,8 +420,9 @@ struct SourceFileDeclFinder {
448
420
const bool exposedProtocolIsExtended =
449
421
ED && !allInheritedProtocolsArePrivate (ED);
450
422
if (ED && !includePrivateDecls && !exposedProtocolIsExtended &&
451
- std::all_of (ED->getMembers ().begin (), ED->getMembers ().end (),
452
- [&](const Decl *D) { return declIsPrivate (D); })) {
423
+ std::all_of (
424
+ ED->getMembers ().begin (), ED->getMembers ().end (),
425
+ [&](const Decl *D) { return D->isPrivateToEnclosingFile (); })) {
453
426
return ;
454
427
}
455
428
if (includePrivateDecls || !ED || exposedProtocolIsExtended)
@@ -485,7 +458,8 @@ struct SourceFileDeclFinder {
485
458
continue ;
486
459
for (const auto *member : ED->getMembers ())
487
460
if (const auto *VD = dyn_cast<ValueDecl>(member))
488
- if (VD->hasName () && (includePrivateDecls || !declIsPrivate (VD))) {
461
+ if (VD->hasName () &&
462
+ (includePrivateDecls || !VD->isPrivateToEnclosingFile ())) {
489
463
const auto *const NTD = ED->getExtendedNominal ();
490
464
if (NTD)
491
465
valuesInExtensions.push_back (std::make_pair (NTD, VD));
@@ -534,7 +508,7 @@ struct SourceFileDeclFinder {
534
508
535
509
// / Return true if \param D should be excluded on privacy grounds.
536
510
bool excludeIfPrivate (const Decl *const D) {
537
- return !includePrivateDecls && declIsPrivate (D );
511
+ return !includePrivateDecls && D-> isPrivateToEnclosingFile ( );
538
512
}
539
513
};
540
514
} // namespace
@@ -642,7 +616,7 @@ class UsedDeclEnumerator {
642
616
std::unordered_set<std::string> holdersOfCascadingMembers;
643
617
for (const auto &p : SF->getReferencedNameTracker ()->getUsedMembers ()) {
644
618
{
645
- bool isPrivate = declIsPrivate ( p.getFirst ().first );
619
+ bool isPrivate = p.getFirst ().first -> isPrivateToEnclosingFile ( );
646
620
if (isPrivate && !includeIntrafileDeps)
647
621
continue ;
648
622
}
@@ -660,7 +634,7 @@ class UsedDeclEnumerator {
660
634
const std::unordered_set<std::string> &&holdersOfCascadingMembers) {
661
635
for (const auto &p : SF->getReferencedNameTracker ()->getUsedMembers ()) {
662
636
{
663
- bool isPrivate = declIsPrivate ( p.getFirst ().first );
637
+ bool isPrivate = p.getFirst ().first -> isPrivateToEnclosingFile ( );
664
638
if (isPrivate && !includeIntrafileDeps)
665
639
continue ;
666
640
}
0 commit comments