Skip to content

Commit def6ad7

Browse files
committed
[Index] Add symbol properties to record the Swift access level of a declaration
This will allow us to record the access level of a Swift symbol in the index store. rdar://163256878
1 parent 626445b commit def6ad7

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

clang/include/clang/Index/IndexSymbol.h

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,38 @@ enum class SymbolSubKind : uint8_t {
110110
typedef uint32_t SymbolPropertySet;
111111
/// Set of properties that provide additional info about a symbol.
112112
enum class SymbolProperty : SymbolPropertySet {
113-
Generic = 1 << 0,
113+
Generic = 1 << 0,
114114
TemplatePartialSpecialization = 1 << 1,
115-
TemplateSpecialization = 1 << 2,
116-
UnitTest = 1 << 3,
117-
IBAnnotated = 1 << 4,
118-
IBOutletCollection = 1 << 5,
119-
GKInspectable = 1 << 6,
120-
Local = 1 << 7,
115+
TemplateSpecialization = 1 << 2,
116+
UnitTest = 1 << 3,
117+
IBAnnotated = 1 << 4,
118+
IBOutletCollection = 1 << 5,
119+
GKInspectable = 1 << 6,
120+
Local = 1 << 7,
121121
/// Symbol is part of a protocol interface.
122-
ProtocolInterface = 1 << 8,
123-
124-
/// Swift-only properties
125-
SwiftAsync = 1 << 16,
122+
ProtocolInterface = 1 << 8,
123+
124+
/// --- Swift-only properties
125+
126+
/// Whether this is a `async` function.
127+
SwiftAsync = 1 << 16,
128+
129+
/// Swift Access control levels, packed into 3 bits.
130+
///
131+
/// Use \c applyForEachSymbolProperty to correctly unpack these from a \c
132+
/// SymbolPropertySet.
133+
SwiftAccessControlPrivate = 1 << 17,
134+
SwiftAccessControlFilePrivate = 1 << 18,
135+
SwiftAccessControlInternal = 1 << 18 | 1 << 17,
136+
SwiftAccessControlPackage = 1 << 19,
137+
SwiftAccessControlPublic = 1 << 19 | 1 << 17,
138+
SwiftAccessControlOpen = 1 << 19 | 1 << 18,
139+
140+
/// Whether the declaration has a `@_spi` attributed.
141+
///
142+
/// Note that `@_spi` is orthogonal to the access control levels because it
143+
/// can be applied to `public` and `open` declarations.
144+
SwiftSPI = 1 << 20,
126145
};
127146

128147
/// Set of roles that are attributed to symbol occurrences.

clang/lib/Index/IndexSymbol.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,14 @@ void index::applyForEachSymbolProperty(SymbolPropertySet Props,
603603
APPLY_FOR_PROPERTY(Local);
604604
APPLY_FOR_PROPERTY(ProtocolInterface);
605605
APPLY_FOR_PROPERTY(SwiftAsync);
606-
606+
APPLY_FOR_PROPERTY(SwiftSPI);
607+
607608
#undef APPLY_FOR_PROPERTY
609+
610+
/// Access levels are bit-packed, so we need to handle them explicitly.
611+
if (uint32_t AccessLevel = Props & (1 << 19 | 1 << 18 | 1 << 17)) {
612+
Fn((SymbolProperty)AccessLevel);
613+
}
608614
}
609615

610616
void index::printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS) {
@@ -625,6 +631,13 @@ void index::printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS) {
625631
case SymbolProperty::Local: OS << "local"; break;
626632
case SymbolProperty::ProtocolInterface: OS << "protocol"; break;
627633
case SymbolProperty::SwiftAsync: OS << "swift_async"; break;
634+
case SymbolProperty::SwiftAccessControlPrivate: OS << "private"; break;
635+
case SymbolProperty::SwiftAccessControlFilePrivate: OS << "fileprivate"; break;
636+
case SymbolProperty::SwiftAccessControlInternal: OS << "internal"; break;
637+
case SymbolProperty::SwiftAccessControlPackage: OS << "package"; break;
638+
case SymbolProperty::SwiftAccessControlPublic: OS << "public"; break;
639+
case SymbolProperty::SwiftAccessControlOpen: OS << "open"; break;
640+
case SymbolProperty::SwiftSPI: OS << "SPI"; break;
628641
}
629642
});
630643
}

0 commit comments

Comments
 (0)