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:
@@ -31,12 +31,11 @@ public:
|
||||
virtual bool enableWarnings() { return false; }
|
||||
|
||||
virtual bool recordHash(StringRef hash, bool isKnown) = 0;
|
||||
virtual bool startDependency(SymbolKind kind, StringRef name, StringRef path,
|
||||
virtual bool startDependency(StringRef name, StringRef path, bool isClangModule,
|
||||
bool isSystem, StringRef hash) = 0;
|
||||
virtual bool finishDependency(SymbolKind kind) = 0;
|
||||
virtual bool finishDependency(bool isClangModule) = 0;
|
||||
virtual Action startSourceEntity(const IndexSymbol &symbol) = 0;
|
||||
virtual bool finishSourceEntity(SymbolKind kind, SymbolSubKindSet subKinds,
|
||||
SymbolRoleSet roles) = 0;
|
||||
virtual bool finishSourceEntity(SymbolInfo symInfo, SymbolRoleSet roles) = 0;
|
||||
|
||||
virtual void finish() {}
|
||||
};
|
||||
|
||||
@@ -20,82 +20,33 @@
|
||||
namespace swift {
|
||||
class Decl;
|
||||
class ValueDecl;
|
||||
enum class AccessorKind;
|
||||
|
||||
namespace index {
|
||||
|
||||
enum class SymbolKind {
|
||||
Unknown,
|
||||
using clang::index::SymbolKind;
|
||||
using clang::index::SymbolLanguage;
|
||||
using clang::index::SymbolSubKind;
|
||||
using clang::index::SymbolProperty;
|
||||
using clang::index::SymbolPropertySet;
|
||||
using clang::index::SymbolRole;
|
||||
using clang::index::SymbolRoleSet;
|
||||
using clang::index::SymbolRelation;
|
||||
using clang::index::SymbolInfo;
|
||||
|
||||
Module,
|
||||
ClangModule, // FIXME: collapse into Module and use a separate Language field.
|
||||
|
||||
Enum,
|
||||
Struct,
|
||||
Class,
|
||||
Protocol,
|
||||
Extension,
|
||||
|
||||
TypeAlias,
|
||||
AssociatedType,
|
||||
GenericTypeParam,
|
||||
|
||||
Function,
|
||||
Variable,
|
||||
PrefixOperator,
|
||||
PostfixOperator,
|
||||
InfixOperator,
|
||||
Accessor,
|
||||
Subscript,
|
||||
EnumElement,
|
||||
|
||||
InstanceMethod,
|
||||
ClassMethod,
|
||||
StaticMethod,
|
||||
InstanceProperty,
|
||||
ClassProperty,
|
||||
StaticProperty,
|
||||
|
||||
Constructor,
|
||||
Destructor,
|
||||
};
|
||||
|
||||
enum class SymbolSubKind : uint32_t {
|
||||
None = 0,
|
||||
|
||||
AccessorGetter = 1 << 0,
|
||||
AccessorSetter = 1 << 1,
|
||||
AccessorWillSet = 1 << 2,
|
||||
AccessorDidSet = 1 << 3,
|
||||
AccessorAddressor = 1 << 4,
|
||||
AccessorMutableAddressor = 1 << 5,
|
||||
|
||||
ExtensionOfStruct = 1 << 6,
|
||||
ExtensionOfClass = 1 << 7,
|
||||
ExtensionOfEnum = 1 << 8,
|
||||
ExtensionOfProtocol = 1 << 9,
|
||||
|
||||
UnitTest = 1 << 10,
|
||||
};
|
||||
|
||||
typedef uint32_t SymbolSubKindSet;
|
||||
|
||||
inline SymbolSubKindSet operator&(SymbolSubKindSet SKSet, SymbolSubKind SK) {
|
||||
return SKSet & (SymbolSubKindSet)SK;
|
||||
inline SymbolPropertySet operator&(SymbolPropertySet SKSet, SymbolProperty SK) {
|
||||
return SKSet & (SymbolPropertySet)SK;
|
||||
}
|
||||
inline SymbolSubKindSet operator|(SymbolSubKindSet SKSet, SymbolSubKind SK) {
|
||||
return SKSet | (SymbolSubKindSet)SK;
|
||||
inline SymbolPropertySet operator|(SymbolPropertySet SKSet, SymbolProperty SK) {
|
||||
return SKSet | (SymbolPropertySet)SK;
|
||||
}
|
||||
inline SymbolSubKindSet &operator|=(SymbolSubKindSet &SKSet, SymbolSubKind SK) {
|
||||
inline SymbolPropertySet &operator|=(SymbolPropertySet &SKSet, SymbolProperty SK) {
|
||||
return SKSet = SKSet | SK;
|
||||
}
|
||||
|
||||
using SymbolRole = clang::index::SymbolRole;
|
||||
using SymbolRoleSet = clang::index::SymbolRoleSet;
|
||||
|
||||
struct IndexRelation {
|
||||
const ValueDecl *decl;
|
||||
SymbolKind kind;
|
||||
SymbolSubKindSet subKinds = SymbolSubKindSet(0);
|
||||
SymbolInfo symInfo;
|
||||
SymbolRoleSet roles = SymbolRoleSet(0);
|
||||
|
||||
// The following strings are guaranteed to live at least as long as the
|
||||
@@ -104,8 +55,8 @@ struct IndexRelation {
|
||||
StringRef USR; // USR may be safely compared by pointer.
|
||||
StringRef group;
|
||||
|
||||
IndexRelation(SymbolRoleSet Roles, const ValueDecl *Sym, SymbolKind Kind, SymbolSubKindSet SubKinds, StringRef Name, StringRef USR)
|
||||
: decl(Sym), kind(Kind), subKinds(SubKinds), roles(Roles), name(Name), USR(USR) {}
|
||||
IndexRelation(SymbolRoleSet Roles, const ValueDecl *Sym, SymbolInfo SymInfo, StringRef Name, StringRef USR)
|
||||
: decl(Sym), symInfo(SymInfo), roles(Roles), name(Name), USR(USR) {}
|
||||
|
||||
IndexRelation() = default;
|
||||
};
|
||||
@@ -126,13 +77,10 @@ struct IndexSymbol : IndexRelation {
|
||||
}
|
||||
};
|
||||
|
||||
SymbolKind getSymbolKindForDecl(const Decl *D);
|
||||
SymbolInfo getSymbolInfoForDecl(const Decl *D);
|
||||
SymbolSubKind getSubKindForAccessor(AccessorKind AK);
|
||||
|
||||
StringRef getSymbolKindString(SymbolKind K);
|
||||
|
||||
void applyForEachSymbolSubKind(SymbolSubKindSet SubKinds,
|
||||
llvm::function_ref<void(SymbolSubKind)> Fn);
|
||||
void printSymbolSubKinds(SymbolSubKindSet SubKinds, raw_ostream &OS);
|
||||
using clang::index::printSymbolProperties;
|
||||
|
||||
} // end namespace index
|
||||
} // end namespace swift
|
||||
|
||||
Reference in New Issue
Block a user