[Index] Record the access level of declarations in the index

rdar://163256878
This commit is contained in:
Alex Hoppen
2025-10-30 14:01:01 +01:00
parent cc777e53bc
commit aa9c295ad5
40 changed files with 469 additions and 372 deletions

View File

@@ -135,54 +135,15 @@ private:
if (!isRef && symbol.decl) {
uidAttrs = getDeclAttributeUIDs(symbol.decl);
info.Attrs = uidAttrs;
if (auto *VD = dyn_cast<ValueDecl>(symbol.decl)) {
if (shouldOutputEffectiveAccessOfValueSymbol(symbol.symInfo)) {
AccessScope accessScope = VD->getFormalAccessScope();
UIdent AttrUID = SwiftLangSupport::getUIDForFormalAccessScope(accessScope);
info.EffectiveAccess = AttrUID;
}
if (auto accessLevel = clang::index::getSwiftAccessLevelFromSymbolPropertySet(
symbol.symInfo.Properties)) {
info.EffectiveAccess =
SwiftLangSupport::getUIDForAccessLevel(*accessLevel);
}
}
return func(info);
}
bool shouldOutputEffectiveAccessOfValueSymbol(SymbolInfo Info) {
SymbolKind Kind = Info.Kind;
SymbolSubKind SubKind = Info.SubKind;
switch (SubKind) {
case SymbolSubKind::AccessorGetter:
case SymbolSubKind::AccessorSetter:
case SymbolSubKind::SwiftAccessorWillSet:
case SymbolSubKind::SwiftAccessorDidSet:
case SymbolSubKind::SwiftAccessorAddressor:
case SymbolSubKind::SwiftAccessorMutableAddressor:
case SymbolSubKind::SwiftGenericTypeParam:
return false;
default:
break;
}
switch (Kind) {
case SymbolKind::Enum:
case SymbolKind::Struct:
case SymbolKind::Class:
case SymbolKind::Protocol:
case SymbolKind::Constructor:
case SymbolKind::EnumConstant:
case SymbolKind::Function:
case SymbolKind::StaticMethod:
case SymbolKind::Variable:
case SymbolKind::InstanceMethod:
case SymbolKind::ClassMethod:
case SymbolKind::InstanceProperty:
case SymbolKind::ClassProperty:
case SymbolKind::StaticProperty:
case SymbolKind::TypeAlias:
return true;
default:
return false;
}
}
template <typename F>
bool withEntityInfo(const IndexRelation &relation, F func) {
EntityInfo info;