mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[index] Use the index symbol types and APIs from the clang header.
This avoids duplication and centralizes handling of symbols.
This commit is contained in:
@@ -40,7 +40,9 @@ using namespace swift;
|
||||
using namespace swift::ide;
|
||||
using swift::index::SymbolKind;
|
||||
using swift::index::SymbolSubKind;
|
||||
using swift::index::SymbolSubKindSet;
|
||||
using swift::index::SymbolProperty;
|
||||
using swift::index::SymbolPropertySet;
|
||||
using swift::index::SymbolInfo;
|
||||
using swift::index::SymbolRole;
|
||||
using swift::index::SymbolRoleSet;
|
||||
|
||||
@@ -548,36 +550,50 @@ getUIDForRangeKind(swift::ide::RangeKind Kind) {
|
||||
}
|
||||
}
|
||||
|
||||
UIdent SwiftLangSupport::getUIDForSymbol(SymbolKind kind, SymbolSubKindSet subKinds,
|
||||
bool isRef) {
|
||||
UIdent SwiftLangSupport::getUIDForSymbol(SymbolInfo sym, bool isRef) {
|
||||
|
||||
#define UID_FOR(CLASS) isRef ? KindRef##CLASS : KindDecl##CLASS;
|
||||
|
||||
switch (sym.SubKind) {
|
||||
default: break;
|
||||
case SymbolSubKind::SwiftAccessorGetter: return UID_FOR(AccessorGetter);
|
||||
case SymbolSubKind::SwiftAccessorSetter: return UID_FOR(AccessorSetter);
|
||||
case SymbolSubKind::SwiftAccessorWillSet: return UID_FOR(AccessorWillSet);
|
||||
case SymbolSubKind::SwiftAccessorDidSet: return UID_FOR(AccessorDidSet);
|
||||
case SymbolSubKind::SwiftAccessorAddressor: return UID_FOR(AccessorAddress);
|
||||
case SymbolSubKind::SwiftAccessorMutableAddressor: return UID_FOR(AccessorMutableAddress);
|
||||
}
|
||||
|
||||
#define SIMPLE_CASE(KIND) \
|
||||
case SymbolKind::KIND: \
|
||||
return UID_FOR(KIND);
|
||||
|
||||
switch (kind) {
|
||||
switch (sym.Kind) {
|
||||
SIMPLE_CASE(Enum)
|
||||
SIMPLE_CASE(Struct)
|
||||
SIMPLE_CASE(Class)
|
||||
SIMPLE_CASE(Protocol)
|
||||
SIMPLE_CASE(TypeAlias)
|
||||
SIMPLE_CASE(AssociatedType)
|
||||
SIMPLE_CASE(GenericTypeParam)
|
||||
SIMPLE_CASE(Subscript)
|
||||
SIMPLE_CASE(EnumElement)
|
||||
SIMPLE_CASE(Constructor)
|
||||
SIMPLE_CASE(Destructor)
|
||||
|
||||
case SymbolKind::EnumConstant:
|
||||
return UID_FOR(EnumElement);
|
||||
|
||||
case SymbolKind::TypeAlias:
|
||||
if (sym.SubKind == SymbolSubKind::SwiftAssociatedType)
|
||||
return UID_FOR(AssociatedType);
|
||||
if (sym.SubKind == SymbolSubKind::SwiftGenericTypeParam)
|
||||
return UID_FOR(GenericTypeParam);
|
||||
return UID_FOR(TypeAlias);
|
||||
|
||||
case SymbolKind::Function:
|
||||
if (sym.SubKind == SymbolSubKind::SwiftPrefixOperator)
|
||||
return UID_FOR(FunctionPrefixOperator);
|
||||
if (sym.SubKind == SymbolSubKind::SwiftPostfixOperator)
|
||||
return UID_FOR(FunctionPostfixOperator);
|
||||
if (sym.SubKind == SymbolSubKind::SwiftInfixOperator)
|
||||
return UID_FOR(FunctionInfixOperator);
|
||||
return UID_FOR(FunctionFree);
|
||||
case SymbolKind::PrefixOperator:
|
||||
return UID_FOR(FunctionPrefixOperator);
|
||||
case SymbolKind::PostfixOperator:
|
||||
return UID_FOR(FunctionPostfixOperator);
|
||||
case SymbolKind::InfixOperator:
|
||||
return UID_FOR(FunctionInfixOperator);
|
||||
case SymbolKind::Variable:
|
||||
return UID_FOR(VarGlobal);
|
||||
case SymbolKind::InstanceMethod:
|
||||
@@ -587,6 +603,8 @@ UIdent SwiftLangSupport::getUIDForSymbol(SymbolKind kind, SymbolSubKindSet subKi
|
||||
case SymbolKind::StaticMethod:
|
||||
return UID_FOR(MethodStatic);
|
||||
case SymbolKind::InstanceProperty:
|
||||
if (sym.SubKind == SymbolSubKind::SwiftSubscript)
|
||||
return UID_FOR(Subscript);
|
||||
return UID_FOR(VarInstance);
|
||||
case SymbolKind::ClassProperty:
|
||||
return UID_FOR(VarClass);
|
||||
@@ -595,32 +613,16 @@ UIdent SwiftLangSupport::getUIDForSymbol(SymbolKind kind, SymbolSubKindSet subKi
|
||||
|
||||
case SymbolKind::Extension:
|
||||
assert(!isRef && "reference to extension decl?");
|
||||
SWIFT_FALLTHROUGH;
|
||||
case SymbolKind::Accessor:
|
||||
if (subKinds & SymbolSubKind::AccessorGetter) {
|
||||
return UID_FOR(AccessorGetter);
|
||||
} else if (subKinds & SymbolSubKind::AccessorSetter) {
|
||||
return UID_FOR(AccessorSetter);
|
||||
} else if (subKinds & SymbolSubKind::AccessorWillSet) {
|
||||
return UID_FOR(AccessorWillSet);
|
||||
} else if (subKinds & SymbolSubKind::AccessorDidSet) {
|
||||
return UID_FOR(AccessorDidSet);
|
||||
} else if (subKinds & SymbolSubKind::AccessorAddressor) {
|
||||
return UID_FOR(AccessorAddress);
|
||||
} else if (subKinds & SymbolSubKind::AccessorMutableAddressor) {
|
||||
return UID_FOR(AccessorMutableAddress);
|
||||
|
||||
} else if (subKinds & SymbolSubKind::ExtensionOfStruct) {
|
||||
if (sym.SubKind == SymbolSubKind::SwiftExtensionOfStruct) {
|
||||
return KindDeclExtensionStruct;
|
||||
} else if (subKinds & SymbolSubKind::ExtensionOfClass) {
|
||||
} else if (sym.SubKind == SymbolSubKind::SwiftExtensionOfClass) {
|
||||
return KindDeclExtensionClass;
|
||||
} else if (subKinds & SymbolSubKind::ExtensionOfEnum) {
|
||||
} else if (sym.SubKind == SymbolSubKind::SwiftExtensionOfEnum) {
|
||||
return KindDeclExtensionEnum;
|
||||
} else if (subKinds & SymbolSubKind::ExtensionOfProtocol) {
|
||||
} else if (sym.SubKind == SymbolSubKind::SwiftExtensionOfProtocol) {
|
||||
return KindDeclExtensionProtocol;
|
||||
|
||||
} else {
|
||||
llvm_unreachable("missing sub kind");
|
||||
llvm_unreachable("missing extension sub kind");
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user