@@ -24,12 +24,16 @@ namespace swift {
24
24
// / a particular declaration can be accessed.
25
25
class AccessScope {
26
26
// / The declaration context (if not public) along with a bit saying
27
- // / whether this scope is private (or not).
27
+ // / whether this scope is private, SPI or not.
28
+ // / If the declaration context is set, the bit means that the scope is
29
+ // / private or not. If the declaration context is null, the bit means that
30
+ // / this scope is SPI or not.
28
31
llvm::PointerIntPair<const DeclContext *, 1 , bool > Value;
32
+
29
33
public:
30
- AccessScope (const DeclContext *DC, bool isPrivate = false );
34
+ AccessScope (const DeclContext *DC, bool isPrivate = false , bool isSPI = false );
31
35
32
- static AccessScope getPublic () { return AccessScope (nullptr ); }
36
+ static AccessScope getPublic (bool isSPI = false ) { return AccessScope (nullptr , false , isSPI ); }
33
37
34
38
// / Check if private access is allowed. This is a lexical scope check in Swift
35
39
// / 3 mode. In Swift 4 mode, declarations and extensions of the same type will
@@ -46,18 +50,24 @@ class AccessScope {
46
50
}
47
51
48
52
bool isPublic () const { return !Value.getPointer (); }
49
- bool isPrivate () const { return Value.getInt (); }
53
+ bool isPrivate () const { return Value.getPointer () && Value. getInt (); }
50
54
bool isFileScope () const ;
51
55
bool isInternal () const ;
52
56
57
+ // Is this a public scope
58
+ bool isSPI () const { return !Value.getPointer () && Value.getInt (); }
59
+
53
60
// / Returns true if this is a child scope of the specified other access scope.
54
61
// /
55
62
// / \see DeclContext::isChildContextOf
56
63
bool isChildOf (AccessScope AS) const {
57
64
if (!isPublic () && !AS.isPublic ())
58
65
return allowsPrivateAccess (getDeclContext (), AS.getDeclContext ());
59
- if (isPublic () && AS.isPublic ())
66
+ if (isPublic () && AS.isPublic ()) {
67
+ if (isSPI () != AS.isSPI ())
68
+ return isSPI ();
60
69
return false ;
70
+ }
61
71
return AS.isPublic ();
62
72
}
63
73
@@ -76,6 +86,8 @@ class AccessScope {
76
86
// / have common intersection, or None if scopes don't intersect.
77
87
const Optional<AccessScope> intersectWith (AccessScope accessScope) const {
78
88
if (hasEqualDeclContextWith (accessScope)) {
89
+ if (isSPI ())
90
+ return *this ;
79
91
if (isPrivate ())
80
92
return *this ;
81
93
return accessScope;
0 commit comments