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 enableWarnings() { return false; }
|
||||||
|
|
||||||
virtual bool recordHash(StringRef hash, bool isKnown) = 0;
|
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;
|
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 Action startSourceEntity(const IndexSymbol &symbol) = 0;
|
||||||
virtual bool finishSourceEntity(SymbolKind kind, SymbolSubKindSet subKinds,
|
virtual bool finishSourceEntity(SymbolInfo symInfo, SymbolRoleSet roles) = 0;
|
||||||
SymbolRoleSet roles) = 0;
|
|
||||||
|
|
||||||
virtual void finish() {}
|
virtual void finish() {}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,82 +20,33 @@
|
|||||||
namespace swift {
|
namespace swift {
|
||||||
class Decl;
|
class Decl;
|
||||||
class ValueDecl;
|
class ValueDecl;
|
||||||
|
enum class AccessorKind;
|
||||||
|
|
||||||
namespace index {
|
namespace index {
|
||||||
|
|
||||||
enum class SymbolKind {
|
using clang::index::SymbolKind;
|
||||||
Unknown,
|
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,
|
inline SymbolPropertySet operator&(SymbolPropertySet SKSet, SymbolProperty SK) {
|
||||||
ClangModule, // FIXME: collapse into Module and use a separate Language field.
|
return SKSet & (SymbolPropertySet)SK;
|
||||||
|
|
||||||
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 SymbolSubKindSet operator|(SymbolSubKindSet SKSet, SymbolSubKind SK) {
|
inline SymbolPropertySet operator|(SymbolPropertySet SKSet, SymbolProperty SK) {
|
||||||
return SKSet | (SymbolSubKindSet)SK;
|
return SKSet | (SymbolPropertySet)SK;
|
||||||
}
|
}
|
||||||
inline SymbolSubKindSet &operator|=(SymbolSubKindSet &SKSet, SymbolSubKind SK) {
|
inline SymbolPropertySet &operator|=(SymbolPropertySet &SKSet, SymbolProperty SK) {
|
||||||
return SKSet = SKSet | SK;
|
return SKSet = SKSet | SK;
|
||||||
}
|
}
|
||||||
|
|
||||||
using SymbolRole = clang::index::SymbolRole;
|
|
||||||
using SymbolRoleSet = clang::index::SymbolRoleSet;
|
|
||||||
|
|
||||||
struct IndexRelation {
|
struct IndexRelation {
|
||||||
const ValueDecl *decl;
|
const ValueDecl *decl;
|
||||||
SymbolKind kind;
|
SymbolInfo symInfo;
|
||||||
SymbolSubKindSet subKinds = SymbolSubKindSet(0);
|
|
||||||
SymbolRoleSet roles = SymbolRoleSet(0);
|
SymbolRoleSet roles = SymbolRoleSet(0);
|
||||||
|
|
||||||
// The following strings are guaranteed to live at least as long as the
|
// 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 USR; // USR may be safely compared by pointer.
|
||||||
StringRef group;
|
StringRef group;
|
||||||
|
|
||||||
IndexRelation(SymbolRoleSet Roles, const ValueDecl *Sym, SymbolKind Kind, SymbolSubKindSet SubKinds, StringRef Name, StringRef USR)
|
IndexRelation(SymbolRoleSet Roles, const ValueDecl *Sym, SymbolInfo SymInfo, StringRef Name, StringRef USR)
|
||||||
: decl(Sym), kind(Kind), subKinds(SubKinds), roles(Roles), name(Name), USR(USR) {}
|
: decl(Sym), symInfo(SymInfo), roles(Roles), name(Name), USR(USR) {}
|
||||||
|
|
||||||
IndexRelation() = default;
|
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);
|
using clang::index::printSymbolProperties;
|
||||||
|
|
||||||
void applyForEachSymbolSubKind(SymbolSubKindSet SubKinds,
|
|
||||||
llvm::function_ref<void(SymbolSubKind)> Fn);
|
|
||||||
void printSymbolSubKinds(SymbolSubKindSet SubKinds, raw_ostream &OS);
|
|
||||||
|
|
||||||
} // end namespace index
|
} // end namespace index
|
||||||
} // end namespace swift
|
} // end namespace swift
|
||||||
|
|||||||
@@ -24,23 +24,6 @@
|
|||||||
using namespace swift;
|
using namespace swift;
|
||||||
using namespace swift::index;
|
using namespace swift::index;
|
||||||
|
|
||||||
static SymbolSubKind getSubKindForAccessor(AccessorKind AK) {
|
|
||||||
switch (AK) {
|
|
||||||
case AccessorKind::NotAccessor: return SymbolSubKind::None;
|
|
||||||
case AccessorKind::IsGetter: return SymbolSubKind::AccessorGetter;
|
|
||||||
case AccessorKind::IsSetter: return SymbolSubKind::AccessorSetter;
|
|
||||||
case AccessorKind::IsWillSet: return SymbolSubKind::AccessorWillSet;
|
|
||||||
case AccessorKind::IsDidSet: return SymbolSubKind::AccessorDidSet;
|
|
||||||
case AccessorKind::IsAddressor: return SymbolSubKind::AccessorAddressor;
|
|
||||||
case AccessorKind::IsMutableAddressor:
|
|
||||||
return SymbolSubKind::AccessorMutableAddressor;
|
|
||||||
case AccessorKind::IsMaterializeForSet:
|
|
||||||
llvm_unreachable("unexpected MaterializeForSet");
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm_unreachable("Unhandled AccessorKind in switch.");
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
printArtificialName(const swift::AbstractStorageDecl *ASD, AccessorKind AK, llvm::raw_ostream &OS) {
|
printArtificialName(const swift::AbstractStorageDecl *ASD, AccessorKind AK, llvm::raw_ostream &OS) {
|
||||||
switch (AK) {
|
switch (AK) {
|
||||||
@@ -132,8 +115,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
|
|||||||
bool isSystemModule = false;
|
bool isSystemModule = false;
|
||||||
struct Entity {
|
struct Entity {
|
||||||
Decl *D;
|
Decl *D;
|
||||||
SymbolKind Kind;
|
SymbolInfo SymInfo;
|
||||||
SymbolSubKindSet SubKinds;
|
|
||||||
SymbolRoleSet Roles;
|
SymbolRoleSet Roles;
|
||||||
SmallVector<SourceLoc, 6> RefsToSuppress;
|
SmallVector<SourceLoc, 6> RefsToSuppress;
|
||||||
};
|
};
|
||||||
@@ -204,17 +186,14 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
|
|||||||
bool addRelation(IndexSymbol &Info, SymbolRoleSet RelationRoles, ValueDecl *D) {
|
bool addRelation(IndexSymbol &Info, SymbolRoleSet RelationRoles, ValueDecl *D) {
|
||||||
assert(D);
|
assert(D);
|
||||||
StringRef Name, USR;
|
StringRef Name, USR;
|
||||||
SymbolKind Kind = getSymbolKindForDecl(D);
|
SymbolInfo SymInfo = getSymbolInfoForDecl(D);
|
||||||
SymbolSubKindSet SubKinds = 0;
|
|
||||||
|
|
||||||
if (Kind == SymbolKind::Unknown)
|
if (SymInfo.Kind == SymbolKind::Unknown)
|
||||||
return true;
|
return true;
|
||||||
if (Kind == SymbolKind::Accessor)
|
|
||||||
SubKinds |= getSubKindForAccessor(cast<FuncDecl>(D)->getAccessorKind());
|
|
||||||
if (getNameAndUSR(D, Name, USR))
|
if (getNameAndUSR(D, Name, USR))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Info.Relations.push_back(IndexRelation(RelationRoles, D, Kind, SubKinds, Name, USR));
|
Info.Relations.push_back(IndexRelation(RelationRoles, D, SymInfo, Name, USR));
|
||||||
Info.roles |= RelationRoles;
|
Info.roles |= RelationRoles;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -371,9 +350,8 @@ private:
|
|||||||
|
|
||||||
bool finishCurrentEntity() {
|
bool finishCurrentEntity() {
|
||||||
Entity CurrEnt = EntitiesStack.pop_back_val();
|
Entity CurrEnt = EntitiesStack.pop_back_val();
|
||||||
assert(CurrEnt.Kind != SymbolKind::Unknown);
|
assert(CurrEnt.SymInfo.Kind != SymbolKind::Unknown);
|
||||||
if (!IdxConsumer.finishSourceEntity(CurrEnt.Kind, CurrEnt.SubKinds,
|
if (!IdxConsumer.finishSourceEntity(CurrEnt.SymInfo, CurrEnt.Roles)) {
|
||||||
CurrEnt.Roles)) {
|
|
||||||
Cancelled = true;
|
Cancelled = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -512,7 +490,7 @@ bool IndexSwiftASTWalker::visitImports(
|
|||||||
if (Path.empty() || Path == TopMod.getFilename())
|
if (Path.empty() || Path == TopMod.getFilename())
|
||||||
continue; // this is a submodule.
|
continue; // this is a submodule.
|
||||||
|
|
||||||
SymbolKind ImportKind = SymbolKind::Unknown;
|
Optional<bool> IsClangModuleOpt;
|
||||||
for (auto File : Mod->getFiles()) {
|
for (auto File : Mod->getFiles()) {
|
||||||
switch (File->getKind()) {
|
switch (File->getKind()) {
|
||||||
case FileUnitKind::Source:
|
case FileUnitKind::Source:
|
||||||
@@ -520,35 +498,36 @@ bool IndexSwiftASTWalker::visitImports(
|
|||||||
case FileUnitKind::Derived:
|
case FileUnitKind::Derived:
|
||||||
break;
|
break;
|
||||||
case FileUnitKind::SerializedAST:
|
case FileUnitKind::SerializedAST:
|
||||||
assert(ImportKind == SymbolKind::Unknown &&
|
assert(!IsClangModuleOpt.hasValue() &&
|
||||||
"cannot handle multi-file modules");
|
"cannot handle multi-file modules");
|
||||||
ImportKind = SymbolKind::Module;
|
IsClangModuleOpt = false;
|
||||||
break;
|
break;
|
||||||
case FileUnitKind::ClangModule:
|
case FileUnitKind::ClangModule:
|
||||||
assert(ImportKind == SymbolKind::Unknown &&
|
assert(!IsClangModuleOpt.hasValue() &&
|
||||||
"cannot handle multi-file modules");
|
"cannot handle multi-file modules");
|
||||||
ImportKind = SymbolKind::ClangModule;
|
IsClangModuleOpt = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ImportKind == SymbolKind::Unknown)
|
if (!IsClangModuleOpt.hasValue())
|
||||||
continue;
|
continue;
|
||||||
|
bool IsClangModule = *IsClangModuleOpt;
|
||||||
|
|
||||||
StringRef Hash;
|
StringRef Hash;
|
||||||
SmallString<32> HashBuf;
|
SmallString<32> HashBuf;
|
||||||
if (ImportKind != SymbolKind::ClangModule) {
|
if (!IsClangModule) {
|
||||||
llvm::raw_svector_ostream HashOS(HashBuf);
|
llvm::raw_svector_ostream HashOS(HashBuf);
|
||||||
getModuleHash(*Mod, HashOS);
|
getModuleHash(*Mod, HashOS);
|
||||||
Hash = HashOS.str();
|
Hash = HashOS.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IdxConsumer.startDependency(ImportKind, Mod->getName().str(), Path,
|
if (!IdxConsumer.startDependency(Mod->getName().str(), Path, IsClangModule,
|
||||||
Mod->isSystemModule(), Hash))
|
Mod->isSystemModule(), Hash))
|
||||||
return false;
|
return false;
|
||||||
if (ImportKind != SymbolKind::ClangModule)
|
if (!IsClangModule)
|
||||||
if (!visitImports(*Mod, Visited))
|
if (!visitImports(*Mod, Visited))
|
||||||
return false;
|
return false;
|
||||||
if (!IdxConsumer.finishDependency(ImportKind))
|
if (!IdxConsumer.finishDependency(IsClangModule))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,7 +542,7 @@ bool IndexSwiftASTWalker::startEntity(Decl *D, IndexSymbol &Info) {
|
|||||||
case swift::index::IndexDataConsumer::Skip:
|
case swift::index::IndexDataConsumer::Skip:
|
||||||
return false;
|
return false;
|
||||||
case swift::index::IndexDataConsumer::Continue:
|
case swift::index::IndexDataConsumer::Continue:
|
||||||
EntitiesStack.push_back({D, Info.kind, Info.subKinds, Info.roles, {}});
|
EntitiesStack.push_back({D, Info.symInfo, Info.roles, {}});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -598,7 +577,8 @@ bool IndexSwiftASTWalker::startEntityDecl(ValueDecl *D) {
|
|||||||
// FIXME handle extensions properly
|
// FIXME handle extensions properly
|
||||||
if (auto ParentVD = dyn_cast<ValueDecl>(Parent)) {
|
if (auto ParentVD = dyn_cast<ValueDecl>(Parent)) {
|
||||||
SymbolRoleSet RelationsToParent = (SymbolRoleSet)SymbolRole::RelationChildOf;
|
SymbolRoleSet RelationsToParent = (SymbolRoleSet)SymbolRole::RelationChildOf;
|
||||||
if (Info.kind == SymbolKind::Accessor)
|
if (Info.symInfo.SubKind >= SymbolSubKind::SwiftAccessorGetter &&
|
||||||
|
Info.symInfo.SubKind <= SymbolSubKind::SwiftAccessorMutableAddressor)
|
||||||
RelationsToParent |= (SymbolRoleSet)SymbolRole::RelationAccessorOf;
|
RelationsToParent |= (SymbolRoleSet)SymbolRole::RelationAccessorOf;
|
||||||
if (addRelation(Info, RelationsToParent, ParentVD))
|
if (addRelation(Info, RelationsToParent, ParentVD))
|
||||||
return false;
|
return false;
|
||||||
@@ -670,8 +650,8 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
|
|||||||
auto updateInfo = [this, D, AccKind](IndexSymbol &Info) {
|
auto updateInfo = [this, D, AccKind](IndexSymbol &Info) {
|
||||||
if (getPseudoAccessorNameAndUSR(D, AccKind, Info.name, Info.USR))
|
if (getPseudoAccessorNameAndUSR(D, AccKind, Info.name, Info.USR))
|
||||||
return true;
|
return true;
|
||||||
Info.kind = SymbolKind::Accessor;
|
Info.symInfo.Kind = SymbolKind::Function;
|
||||||
Info.subKinds |= getSubKindForAccessor(AccKind);
|
Info.symInfo.SubKind = getSubKindForAccessor(AccKind);
|
||||||
Info.roles |= (SymbolRoleSet)SymbolRole::Implicit;
|
Info.roles |= (SymbolRoleSet)SymbolRole::Implicit;
|
||||||
Info.group = "";
|
Info.group = "";
|
||||||
return false;
|
return false;
|
||||||
@@ -684,7 +664,7 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
|
|||||||
if (updateInfo(Info))
|
if (updateInfo(Info))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.kind, Info.subKinds, Info.roles))
|
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles))
|
||||||
Cancelled = true;
|
Cancelled = true;
|
||||||
} else {
|
} else {
|
||||||
IndexSymbol Info;
|
IndexSymbol Info;
|
||||||
@@ -695,7 +675,7 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
|
|||||||
if (addRelation(Info, (SymbolRoleSet) SymbolRole::RelationAccessorOf, D))
|
if (addRelation(Info, (SymbolRoleSet) SymbolRole::RelationAccessorOf, D))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.kind, Info.subKinds, Info.roles))
|
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles))
|
||||||
Cancelled = true;
|
Cancelled = true;
|
||||||
}
|
}
|
||||||
return !Cancelled;
|
return !Cancelled;
|
||||||
@@ -727,17 +707,7 @@ bool IndexSwiftASTWalker::reportExtension(ExtensionDecl *D) {
|
|||||||
if (initIndexSymbol(NTD, Loc, /*IsRef=*/false, Info))
|
if (initIndexSymbol(NTD, Loc, /*IsRef=*/false, Info))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Info.kind = getSymbolKindForDecl(D);
|
Info.symInfo = getSymbolInfoForDecl(D);
|
||||||
if (isa<StructDecl>(NTD))
|
|
||||||
Info.subKinds |= SymbolSubKind::ExtensionOfStruct;
|
|
||||||
else if (isa<ClassDecl>(NTD))
|
|
||||||
Info.subKinds |= SymbolSubKind::ExtensionOfClass;
|
|
||||||
else if (isa<EnumDecl>(NTD))
|
|
||||||
Info.subKinds |= SymbolSubKind::ExtensionOfEnum;
|
|
||||||
else if (isa<ProtocolDecl>(NTD))
|
|
||||||
Info.subKinds |= SymbolSubKind::ExtensionOfProtocol;
|
|
||||||
|
|
||||||
assert(Info.subKinds != 0);
|
|
||||||
|
|
||||||
if (!startEntity(D, Info))
|
if (!startEntity(D, Info))
|
||||||
return false;
|
return false;
|
||||||
@@ -850,12 +820,10 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
|
|||||||
bool IsRef, IndexSymbol &Info) {
|
bool IsRef, IndexSymbol &Info) {
|
||||||
assert(D);
|
assert(D);
|
||||||
Info.decl = D;
|
Info.decl = D;
|
||||||
Info.kind = getSymbolKindForDecl(D);
|
Info.symInfo = getSymbolInfoForDecl(D);
|
||||||
if (Info.kind == SymbolKind::Unknown)
|
if (Info.symInfo.Kind == SymbolKind::Unknown)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (Info.kind == SymbolKind::Accessor)
|
|
||||||
Info.subKinds |= getSubKindForAccessor(cast<FuncDecl>(D)->getAccessorKind());
|
|
||||||
// Cannot be extension, which is not a ValueDecl.
|
// Cannot be extension, which is not a ValueDecl.
|
||||||
|
|
||||||
if (IsRef)
|
if (IsRef)
|
||||||
@@ -931,7 +899,7 @@ bool IndexSwiftASTWalker::initFuncDeclIndexSymbol(ValueDecl *D,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (isTestCandidate(D))
|
if (isTestCandidate(D))
|
||||||
Info.subKinds |= SymbolSubKind::UnitTest;
|
Info.symInfo.Properties |= SymbolProperty::UnitTest;
|
||||||
|
|
||||||
if (auto Group = D->getGroupName())
|
if (auto Group = D->getGroupName())
|
||||||
Info.group = Group.getValue();
|
Info.group = Group.getValue();
|
||||||
|
|||||||
@@ -11,35 +11,45 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "swift/Index/IndexSymbol.h"
|
#include "swift/Index/IndexSymbol.h"
|
||||||
#include "swift/AST/Decl.h"
|
#include "swift/AST/AST.h"
|
||||||
|
|
||||||
using namespace swift;
|
using namespace swift;
|
||||||
using namespace swift::index;
|
using namespace swift::index;
|
||||||
|
|
||||||
static SymbolKind getFuncSymbolKind(const FuncDecl *FD) {
|
static void setFuncSymbolInfo(const FuncDecl *FD, SymbolInfo &sym) {
|
||||||
if (FD->isAccessor())
|
sym.Kind = SymbolKind::Function;
|
||||||
return SymbolKind::Accessor;
|
|
||||||
|
|
||||||
if (auto *op = FD->getOperatorDecl()) {
|
|
||||||
switch (op->getKind()) {
|
|
||||||
case DeclKind::PrefixOperator: return SymbolKind::PrefixOperator;
|
|
||||||
case DeclKind::PostfixOperator: return SymbolKind::PostfixOperator;
|
|
||||||
case DeclKind::InfixOperator: return SymbolKind::InfixOperator;
|
|
||||||
default:
|
|
||||||
llvm_unreachable("unexpected operator kind");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FD->getDeclContext()->isTypeContext()) {
|
if (FD->getDeclContext()->isTypeContext()) {
|
||||||
if (FD->isStatic()) {
|
if (FD->isStatic()) {
|
||||||
if (FD->getCorrectStaticSpelling() == StaticSpellingKind::KeywordClass)
|
if (FD->getCorrectStaticSpelling() == StaticSpellingKind::KeywordClass)
|
||||||
return SymbolKind::ClassMethod;
|
sym.Kind = SymbolKind::ClassMethod;
|
||||||
return SymbolKind::StaticMethod;
|
else
|
||||||
|
sym.Kind = SymbolKind::StaticMethod;
|
||||||
|
} else {
|
||||||
|
sym.Kind = SymbolKind::InstanceMethod;
|
||||||
}
|
}
|
||||||
return SymbolKind::InstanceMethod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SymbolKind::Function;
|
if (FD->isAccessor()) {
|
||||||
|
sym.SubKind = getSubKindForAccessor(FD->getAccessorKind());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto *op = FD->getOperatorDecl()) {
|
||||||
|
switch (op->getKind()) {
|
||||||
|
case DeclKind::PrefixOperator:
|
||||||
|
sym.SubKind = SymbolSubKind::SwiftPrefixOperator;
|
||||||
|
return;
|
||||||
|
case DeclKind::PostfixOperator:
|
||||||
|
sym.SubKind = SymbolSubKind::SwiftPostfixOperator;
|
||||||
|
return;
|
||||||
|
case DeclKind::InfixOperator:
|
||||||
|
sym.SubKind = SymbolSubKind::SwiftInfixOperator;
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
llvm_unreachable("unexpected operator kind");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SymbolKind getVarSymbolKind(const VarDecl *VD) {
|
static SymbolKind getVarSymbolKind(const VarDecl *VD) {
|
||||||
@@ -57,107 +67,79 @@ static SymbolKind getVarSymbolKind(const VarDecl *VD) {
|
|||||||
return SymbolKind::Variable;
|
return SymbolKind::Variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
SymbolKind index::getSymbolKindForDecl(const Decl *D) {
|
SymbolInfo index::getSymbolInfoForDecl(const Decl *D) {
|
||||||
|
SymbolInfo info{ SymbolKind::Unknown, SymbolSubKind::None,
|
||||||
|
SymbolPropertySet(), SymbolLanguage::Swift };
|
||||||
switch (D->getKind()) {
|
switch (D->getKind()) {
|
||||||
case DeclKind::Enum: return SymbolKind::Enum;
|
case DeclKind::Enum: info.Kind = SymbolKind::Enum; break;
|
||||||
case DeclKind::Struct: return SymbolKind::Struct;
|
case DeclKind::Struct: info.Kind = SymbolKind::Struct; break;
|
||||||
case DeclKind::Class: return SymbolKind::Class;
|
case DeclKind::Class: info.Kind = SymbolKind::Class; break;
|
||||||
case DeclKind::Protocol: return SymbolKind::Protocol;
|
case DeclKind::Protocol: info.Kind = SymbolKind::Protocol; break;
|
||||||
case DeclKind::Extension: return SymbolKind::Extension;
|
case DeclKind::Extension: {
|
||||||
case DeclKind::TypeAlias: return SymbolKind::TypeAlias;
|
info.Kind = SymbolKind::Extension;
|
||||||
case DeclKind::AssociatedType: return SymbolKind::AssociatedType;
|
auto *ED = cast<ExtensionDecl>(D);
|
||||||
case DeclKind::GenericTypeParam: return SymbolKind::GenericTypeParam;
|
if (!ED->getExtendedType())
|
||||||
case DeclKind::EnumElement: return SymbolKind::EnumElement;
|
break;
|
||||||
case DeclKind::Subscript: return SymbolKind::Subscript;
|
NominalTypeDecl *NTD = ED->getExtendedType()->getAnyNominal();
|
||||||
case DeclKind::Constructor: return SymbolKind::Constructor;
|
if (!NTD)
|
||||||
case DeclKind::Destructor: return SymbolKind::Destructor;
|
break;
|
||||||
|
if (isa<StructDecl>(NTD))
|
||||||
|
info.SubKind = SymbolSubKind::SwiftExtensionOfStruct;
|
||||||
|
else if (isa<ClassDecl>(NTD))
|
||||||
|
info.SubKind = SymbolSubKind::SwiftExtensionOfClass;
|
||||||
|
else if (isa<EnumDecl>(NTD))
|
||||||
|
info.SubKind = SymbolSubKind::SwiftExtensionOfEnum;
|
||||||
|
else if (isa<ProtocolDecl>(NTD))
|
||||||
|
info.SubKind = SymbolSubKind::SwiftExtensionOfProtocol;
|
||||||
|
assert(info.SubKind != SymbolSubKind::None);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DeclKind::TypeAlias: info.Kind = SymbolKind::TypeAlias; break;
|
||||||
|
case DeclKind::AssociatedType:
|
||||||
|
info.Kind = SymbolKind::TypeAlias;
|
||||||
|
info.SubKind = SymbolSubKind::SwiftAssociatedType;
|
||||||
|
break;
|
||||||
|
case DeclKind::GenericTypeParam:
|
||||||
|
info.Kind = SymbolKind::TypeAlias;
|
||||||
|
info.SubKind = SymbolSubKind::SwiftGenericTypeParam;
|
||||||
|
break;
|
||||||
|
case DeclKind::EnumElement: info.Kind = SymbolKind::EnumConstant; break;
|
||||||
|
case DeclKind::Subscript:
|
||||||
|
info.Kind = SymbolKind::InstanceProperty;
|
||||||
|
info.SubKind = SymbolSubKind::SwiftSubscript;
|
||||||
|
break;
|
||||||
|
case DeclKind::Constructor: info.Kind = SymbolKind::Constructor; break;
|
||||||
|
case DeclKind::Destructor: info.Kind = SymbolKind::Destructor; break;;
|
||||||
case DeclKind::Param:
|
case DeclKind::Param:
|
||||||
llvm_unreachable("unexpected parameter seen while indexing");
|
llvm_unreachable("unexpected parameter seen while indexing");
|
||||||
|
|
||||||
case DeclKind::Func:
|
case DeclKind::Func:
|
||||||
return getFuncSymbolKind(cast<FuncDecl>(D));
|
setFuncSymbolInfo(cast<FuncDecl>(D), info);
|
||||||
|
break;
|
||||||
case DeclKind::Var:
|
case DeclKind::Var:
|
||||||
return getVarSymbolKind(cast<VarDecl>(D));
|
info.Kind = getVarSymbolKind(cast<VarDecl>(D));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return SymbolKind::Unknown;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringRef index::getSymbolKindString(SymbolKind K) {
|
SymbolSubKind index::getSubKindForAccessor(AccessorKind AK) {
|
||||||
switch (K) {
|
switch (AK) {
|
||||||
case SymbolKind::Unknown: return "<unknown>";
|
case AccessorKind::NotAccessor: return SymbolSubKind::None;
|
||||||
case SymbolKind::Module: return "module";
|
case AccessorKind::IsGetter: return SymbolSubKind::SwiftAccessorGetter;
|
||||||
case SymbolKind::ClangModule: return "clang-module";
|
case AccessorKind::IsSetter: return SymbolSubKind::SwiftAccessorSetter;
|
||||||
case SymbolKind::Enum: return "enum";
|
case AccessorKind::IsWillSet: return SymbolSubKind::SwiftAccessorWillSet;
|
||||||
case SymbolKind::EnumElement: return "enum-element";
|
case AccessorKind::IsDidSet: return SymbolSubKind::SwiftAccessorDidSet;
|
||||||
case SymbolKind::Struct: return "struct";
|
case AccessorKind::IsAddressor: return SymbolSubKind::SwiftAccessorAddressor;
|
||||||
case SymbolKind::Class: return "class";
|
case AccessorKind::IsMutableAddressor:
|
||||||
case SymbolKind::Protocol: return "protocol";
|
return SymbolSubKind::SwiftAccessorMutableAddressor;
|
||||||
case SymbolKind::Extension: return "extension";
|
case AccessorKind::IsMaterializeForSet:
|
||||||
case SymbolKind::TypeAlias: return "type-alias";
|
llvm_unreachable("unexpected MaterializeForSet");
|
||||||
case SymbolKind::Function: return "function";
|
|
||||||
case SymbolKind::Variable: return "variable";
|
|
||||||
case SymbolKind::InstanceMethod: return "instance-method";
|
|
||||||
case SymbolKind::ClassMethod: return "class-method";
|
|
||||||
case SymbolKind::StaticMethod: return "static-method";
|
|
||||||
case SymbolKind::InstanceProperty: return "instance-property";
|
|
||||||
case SymbolKind::ClassProperty: return "class-property";
|
|
||||||
case SymbolKind::StaticProperty: return "static-property";
|
|
||||||
case SymbolKind::Constructor: return "constructor";
|
|
||||||
case SymbolKind::Destructor: return "destructor";
|
|
||||||
case SymbolKind::PrefixOperator: return "prefix-operator";
|
|
||||||
case SymbolKind::PostfixOperator: return "postfix-operator";
|
|
||||||
case SymbolKind::InfixOperator: return "infix-operator";
|
|
||||||
case SymbolKind::Accessor: return "accessor";
|
|
||||||
case SymbolKind::Subscript: return "subscript";
|
|
||||||
case SymbolKind::AssociatedType: return "associated-type";
|
|
||||||
case SymbolKind::GenericTypeParam: return "generic-type-param";
|
|
||||||
}
|
}
|
||||||
llvm_unreachable("invalid symbol kind");
|
|
||||||
}
|
llvm_unreachable("Unhandled AccessorKind in switch.");
|
||||||
|
|
||||||
void index::applyForEachSymbolSubKind(SymbolSubKindSet SubKinds,
|
|
||||||
llvm::function_ref<void(SymbolSubKind)> Fn) {
|
|
||||||
#define APPLY_FOR_SUBKIND(K) \
|
|
||||||
if (SubKinds & (unsigned)SymbolSubKind::K) \
|
|
||||||
Fn(SymbolSubKind::K)
|
|
||||||
|
|
||||||
APPLY_FOR_SUBKIND(AccessorGetter);
|
|
||||||
APPLY_FOR_SUBKIND(AccessorSetter);
|
|
||||||
APPLY_FOR_SUBKIND(AccessorWillSet);
|
|
||||||
APPLY_FOR_SUBKIND(AccessorDidSet);
|
|
||||||
APPLY_FOR_SUBKIND(AccessorAddressor);
|
|
||||||
APPLY_FOR_SUBKIND(AccessorMutableAddressor);
|
|
||||||
APPLY_FOR_SUBKIND(ExtensionOfStruct);
|
|
||||||
APPLY_FOR_SUBKIND(ExtensionOfClass);
|
|
||||||
APPLY_FOR_SUBKIND(ExtensionOfEnum);
|
|
||||||
APPLY_FOR_SUBKIND(ExtensionOfProtocol);
|
|
||||||
APPLY_FOR_SUBKIND(UnitTest);
|
|
||||||
|
|
||||||
#undef APPLY_FOR_SUBKIND
|
|
||||||
}
|
|
||||||
|
|
||||||
void index::printSymbolSubKinds(SymbolSubKindSet SubKinds, raw_ostream &OS) {
|
|
||||||
bool VisitedOnce = false;
|
|
||||||
applyForEachSymbolSubKind(SubKinds, [&](SymbolSubKind SubKind) {
|
|
||||||
if (VisitedOnce)
|
|
||||||
OS << ',';
|
|
||||||
else
|
|
||||||
VisitedOnce = true;
|
|
||||||
switch (SubKind) {
|
|
||||||
case SymbolSubKind::None: OS << "none"; break;
|
|
||||||
case SymbolSubKind::UnitTest: OS << "test"; break;
|
|
||||||
case SymbolSubKind::AccessorGetter: OS << "get"; break;
|
|
||||||
case SymbolSubKind::AccessorSetter: OS << "set"; break;
|
|
||||||
case SymbolSubKind::AccessorWillSet: OS << "willSet"; break;
|
|
||||||
case SymbolSubKind::AccessorDidSet: OS << "didSet"; break;
|
|
||||||
case SymbolSubKind::AccessorAddressor: OS << "addr"; break;
|
|
||||||
case SymbolSubKind::AccessorMutableAddressor: OS << "mutAddr"; break;
|
|
||||||
case SymbolSubKind::ExtensionOfStruct: OS << "extStruct"; break;
|
|
||||||
case SymbolSubKind::ExtensionOfClass: OS << "extClass"; break;
|
|
||||||
case SymbolSubKind::ExtensionOfEnum: OS << "extEnum"; break;
|
|
||||||
case SymbolSubKind::ExtensionOfProtocol: OS << "extProt"; break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ enum AnEnumeration {
|
|||||||
|
|
||||||
// EnumElement
|
// EnumElement
|
||||||
case Element
|
case Element
|
||||||
// CHECK: [[@LINE-1]]:8 | enum-element/Swift | Element | s:FO14swift_ide_test13AnEnumeration7ElementFMS0_S0_ | Def,RelChild | rel: 1
|
// CHECK: [[@LINE-1]]:8 | enumerator/Swift | Element | s:FO14swift_ide_test13AnEnumeration7ElementFMS0_S0_ | Def,RelChild | rel: 1
|
||||||
// CHECK-NEXT: RelChild | AnEnumeration | s:O14swift_ide_test13AnEnumeration
|
// CHECK-NEXT: RelChild | AnEnumeration | s:O14swift_ide_test13AnEnumeration
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,12 +18,12 @@ struct AStruct {
|
|||||||
|
|
||||||
// Subscript
|
// Subscript
|
||||||
subscript(index: Int) -> Int {
|
subscript(index: Int) -> Int {
|
||||||
// CHECK: [[@LINE-1]]:3 | subscript/Swift | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi | Def,RelChild | rel: 1
|
// CHECK: [[@LINE-1]]:3 | instance-property/subscript/Swift | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi | Def,RelChild | rel: 1
|
||||||
// CHECK-NEXT: RelChild | AStruct | s:V14swift_ide_test7AStruct
|
// CHECK-NEXT: RelChild | AStruct | s:V14swift_ide_test7AStruct
|
||||||
|
|
||||||
// Accessor + AccessorAddressor
|
// Accessor + AccessorAddressor
|
||||||
unsafeAddress {
|
unsafeAddress {
|
||||||
// CHECK: [[@LINE-1]]:5 | accessor(addr)/Swift | | s:FV14swift_ide_test7AStructlu9subscriptFSiSi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:5 | instance-method/acc-addr/Swift | | s:FV14swift_ide_test7AStructlu9subscriptFSiSi | Def,RelChild,RelAcc | rel: 1
|
||||||
// CHECK-NEXT: RelChild,RelAcc | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi
|
// CHECK-NEXT: RelChild,RelAcc | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi
|
||||||
|
|
||||||
return UnsafePointer(base)
|
return UnsafePointer(base)
|
||||||
@@ -31,7 +31,7 @@ struct AStruct {
|
|||||||
|
|
||||||
// Accessor + AccessorMutableAddressor
|
// Accessor + AccessorMutableAddressor
|
||||||
unsafeMutableAddress {
|
unsafeMutableAddress {
|
||||||
// CHECK: [[@LINE-1]]:5 | accessor(mutAddr)/Swift | | s:FV14swift_ide_test7AStructau9subscriptFSiSi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:5 | instance-method/acc-mutaddr/Swift | | s:FV14swift_ide_test7AStructau9subscriptFSiSi | Def,RelChild,RelAcc | rel: 1
|
||||||
// CHECK-NEXT: RelChild,RelAcc | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi
|
// CHECK-NEXT: RelChild,RelAcc | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi
|
||||||
|
|
||||||
return base
|
return base
|
||||||
@@ -65,7 +65,7 @@ class AClass {
|
|||||||
|
|
||||||
// Accessor + AccessorGetter
|
// Accessor + AccessorGetter
|
||||||
get {
|
get {
|
||||||
// CHECK: [[@LINE-1]]:5 | accessor(get)/Swift | getter:instanceProperty | s:FC14swift_ide_test6AClassg16instancePropertySi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:5 | instance-method/acc-get/Swift | getter:instanceProperty | s:FC14swift_ide_test6AClassg16instancePropertySi | Def,RelChild,RelAcc | rel: 1
|
||||||
// CHECK-NEXT: RelChild,RelAcc | instanceProperty | s:vC14swift_ide_test6AClass16instancePropertySi
|
// CHECK-NEXT: RelChild,RelAcc | instanceProperty | s:vC14swift_ide_test6AClass16instancePropertySi
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
@@ -73,7 +73,7 @@ class AClass {
|
|||||||
|
|
||||||
// Accessor + AccessorSetter
|
// Accessor + AccessorSetter
|
||||||
set {}
|
set {}
|
||||||
// CHECK: [[@LINE-1]]:5 | accessor(set)/Swift | setter:instanceProperty | s:FC14swift_ide_test6AClasss16instancePropertySi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:5 | instance-method/acc-set/Swift | setter:instanceProperty | s:FC14swift_ide_test6AClasss16instancePropertySi | Def,RelChild,RelAcc | rel: 1
|
||||||
// CHECK-NEXT: RelChild,RelAcc | instanceProperty | s:vC14swift_ide_test6AClass16instancePropertySi
|
// CHECK-NEXT: RelChild,RelAcc | instanceProperty | s:vC14swift_ide_test6AClass16instancePropertySi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,12 +81,12 @@ class AClass {
|
|||||||
|
|
||||||
// Accessor + AccessorWillSet
|
// Accessor + AccessorWillSet
|
||||||
willSet {}
|
willSet {}
|
||||||
// CHECK: [[@LINE-1]]:5 | accessor(willSet)/Swift | willSet:observed | s:FC14swift_ide_test6AClassw8observedSi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:5 | instance-method/acc-willset/Swift | willSet:observed | s:FC14swift_ide_test6AClassw8observedSi | Def,RelChild,RelAcc | rel: 1
|
||||||
// CHECK-NEXT: RelChild,RelAcc | observed | s:vC14swift_ide_test6AClass8observedSi
|
// CHECK-NEXT: RelChild,RelAcc | observed | s:vC14swift_ide_test6AClass8observedSi
|
||||||
|
|
||||||
// Accessor + AccessorDidSet
|
// Accessor + AccessorDidSet
|
||||||
didSet {}
|
didSet {}
|
||||||
// CHECK: [[@LINE-1]]:5 | accessor(didSet)/Swift | didSet:observed | s:FC14swift_ide_test6AClassW8observedSi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:5 | instance-method/acc-didset/Swift | didSet:observed | s:FC14swift_ide_test6AClassW8observedSi | Def,RelChild,RelAcc | rel: 1
|
||||||
// CHECK-NEXT: RelChild,RelAcc | observed | s:vC14swift_ide_test6AClass8observedSi
|
// CHECK-NEXT: RelChild,RelAcc | observed | s:vC14swift_ide_test6AClass8observedSi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,28 +117,28 @@ protocol AProtocol {
|
|||||||
|
|
||||||
// AssociatedType
|
// AssociatedType
|
||||||
associatedtype T
|
associatedtype T
|
||||||
// CHECK: [[@LINE-1]]:18 | associated-type/Swift | T | s:P14swift_ide_test9AProtocol1T | Def,RelChild | rel: 1
|
// CHECK: [[@LINE-1]]:18 | type-alias/associated-type/Swift | T | s:P14swift_ide_test9AProtocol1T | Def,RelChild | rel: 1
|
||||||
// CHECK-NEXT: RelChild | AProtocol | s:P14swift_ide_test9AProtocol
|
// CHECK-NEXT: RelChild | AProtocol | s:P14swift_ide_test9AProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extension
|
// Extension
|
||||||
extension AnEnumeration {}
|
extension AnEnumeration {}
|
||||||
// CHECK: [[@LINE-1]]:11 | extension(extEnum)/Swift | AnEnumeration | s:O14swift_ide_test13AnEnumeration | Def | rel: 0
|
// CHECK: [[@LINE-1]]:11 | extension/ext-enum/Swift | AnEnumeration | s:O14swift_ide_test13AnEnumeration | Def | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:11 | enum/Swift | AnEnumeration | s:O14swift_ide_test13AnEnumeration | Ref,RelExt | rel: 1
|
// CHECK: [[@LINE-2]]:11 | enum/Swift | AnEnumeration | s:O14swift_ide_test13AnEnumeration | Ref,RelExt | rel: 1
|
||||||
// CHECK-NEXT: RelExt | AnEnumeration | s:O14swift_ide_test13AnEnumeration
|
// CHECK-NEXT: RelExt | AnEnumeration | s:O14swift_ide_test13AnEnumeration
|
||||||
|
|
||||||
extension AStruct {}
|
extension AStruct {}
|
||||||
// CHECK: [[@LINE-1]]:11 | extension(extStruct)/Swift | AStruct | s:V14swift_ide_test7AStruct | Def | rel: 0
|
// CHECK: [[@LINE-1]]:11 | extension/ext-struct/Swift | AStruct | s:V14swift_ide_test7AStruct | Def | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:11 | struct/Swift | AStruct | s:V14swift_ide_test7AStruct | Ref,RelExt | rel: 1
|
// CHECK: [[@LINE-2]]:11 | struct/Swift | AStruct | s:V14swift_ide_test7AStruct | Ref,RelExt | rel: 1
|
||||||
// CHECK-NEXT: RelExt | AStruct | s:V14swift_ide_test7AStruct
|
// CHECK-NEXT: RelExt | AStruct | s:V14swift_ide_test7AStruct
|
||||||
|
|
||||||
extension AClass {}
|
extension AClass {}
|
||||||
// CHECK: [[@LINE-1]]:11 | extension(extClass)/Swift | AClass | s:C14swift_ide_test6AClass | Def | rel: 0
|
// CHECK: [[@LINE-1]]:11 | extension/ext-class/Swift | AClass | s:C14swift_ide_test6AClass | Def | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:11 | class/Swift | AClass | s:C14swift_ide_test6AClass | Ref,RelExt | rel: 1
|
// CHECK: [[@LINE-2]]:11 | class/Swift | AClass | s:C14swift_ide_test6AClass | Ref,RelExt | rel: 1
|
||||||
// CHECK-NEXT: RelExt | AClass | s:C14swift_ide_test6AClass
|
// CHECK-NEXT: RelExt | AClass | s:C14swift_ide_test6AClass
|
||||||
|
|
||||||
extension AProtocol {}
|
extension AProtocol {}
|
||||||
// CHECK: [[@LINE-1]]:11 | extension(extProt)/Swift | AProtocol | s:P14swift_ide_test9AProtocol | Def | rel: 0
|
// CHECK: [[@LINE-1]]:11 | extension/ext-protocol/Swift | AProtocol | s:P14swift_ide_test9AProtocol | Def | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:11 | protocol/Swift | AProtocol | s:P14swift_ide_test9AProtocol | Ref,RelExt | rel: 1
|
// CHECK: [[@LINE-2]]:11 | protocol/Swift | AProtocol | s:P14swift_ide_test9AProtocol | Ref,RelExt | rel: 1
|
||||||
// CHECK-NEXT: RelExt | AProtocol | s:P14swift_ide_test9AProtocol
|
// CHECK-NEXT: RelExt | AProtocol | s:P14swift_ide_test9AProtocol
|
||||||
|
|
||||||
@@ -149,11 +149,11 @@ typealias SomeAlias = AStruct
|
|||||||
|
|
||||||
// GenericTypeParam
|
// GenericTypeParam
|
||||||
struct GenericStruct<ATypeParam> {}
|
struct GenericStruct<ATypeParam> {}
|
||||||
// CHECK: [[@LINE-1]]:22 | generic-type-param/Swift | ATypeParam | s:tV14swift_ide_test13GenericStruct10ATypeParamMx | Def,RelChild | rel: 1
|
// CHECK: [[@LINE-1]]:22 | type-alias/generic-type-param/Swift | ATypeParam | s:tV14swift_ide_test13GenericStruct10ATypeParamMx | Def,RelChild | rel: 1
|
||||||
// CHECK-NEXT: RelChild | GenericStruct | s:V14swift_ide_test13GenericStruct
|
// CHECK-NEXT: RelChild | GenericStruct | s:V14swift_ide_test13GenericStruct
|
||||||
|
|
||||||
func GenericFunc<ATypeParam>(_: ATypeParam) {}
|
func GenericFunc<ATypeParam>(_: ATypeParam) {}
|
||||||
// CHECK-NOT: [[@LINE-1]]:18 | generic-type-param/Swift | ATypeParam | {{.*}} | Def,RelChild | rel: 1
|
// CHECK-NOT: [[@LINE-1]]:18 | type-alias/generic-type-param/Swift | ATypeParam | {{.*}} | Def,RelChild | rel: 1
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
func EmptyFunction() {}
|
func EmptyFunction() {}
|
||||||
@@ -165,15 +165,15 @@ var foo = 1
|
|||||||
|
|
||||||
// PrefixOperator
|
// PrefixOperator
|
||||||
prefix func -(a: AStruct) -> AStruct { return a }
|
prefix func -(a: AStruct) -> AStruct { return a }
|
||||||
// CHECK: [[@LINE-1]]:13 | prefix-operator/Swift | -(_:) | s:F14swift_ide_testop1sFVS_7AStructS0_ | Def | rel: 0
|
// CHECK: [[@LINE-1]]:13 | function/prefix-operator/Swift | -(_:) | s:F14swift_ide_testop1sFVS_7AStructS0_ | Def | rel: 0
|
||||||
|
|
||||||
// PostfixOperator
|
// PostfixOperator
|
||||||
postfix func ++(a: AStruct) -> AStruct { return a }
|
postfix func ++(a: AStruct) -> AStruct { return a }
|
||||||
// CHECK: [[@LINE-1]]:14 | postfix-operator/Swift | ++(_:) | s:F14swift_ide_testoP2ppFVS_7AStructS0_ | Def | rel: 0
|
// CHECK: [[@LINE-1]]:14 | function/postfix-operator/Swift | ++(_:) | s:F14swift_ide_testoP2ppFVS_7AStructS0_ | Def | rel: 0
|
||||||
|
|
||||||
// InfixOperator
|
// InfixOperator
|
||||||
func +(a: AStruct, b: AStruct) -> AStruct { return a }
|
func +(a: AStruct, b: AStruct) -> AStruct { return a }
|
||||||
// CHECK: [[@LINE-1]]:6 | infix-operator/Swift | +(_:_:) | s:F14swift_ide_testoi1pFTVS_7AStructS0__S0_ | Def | rel: 0
|
// CHECK: [[@LINE-1]]:6 | function/infix-operator/Swift | +(_:_:) | s:F14swift_ide_testoi1pFTVS_7AStructS0__S0_ | Def | rel: 0
|
||||||
|
|
||||||
|
|
||||||
// TODO: UnitTest
|
// TODO: UnitTest
|
||||||
|
|||||||
@@ -8,30 +8,30 @@ let x = 2
|
|||||||
var y = x + 1
|
var y = x + 1
|
||||||
// CHECK: [[@LINE-1]]:5 | variable/Swift | y | s:v14swift_ide_test1ySi | Def | rel: 0
|
// CHECK: [[@LINE-1]]:5 | variable/Swift | y | s:v14swift_ide_test1ySi | Def | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:9 | variable/Swift | x | s:v14swift_ide_test1xSi | Ref,Read | rel: 0
|
// CHECK: [[@LINE-2]]:9 | variable/Swift | x | s:v14swift_ide_test1xSi | Ref,Read | rel: 0
|
||||||
// CHECK: [[@LINE-3]]:11 | infix-operator/Swift | +(_:_:) | s:Fsoi1pFTSiSi_Si | Ref,Call | rel: 0
|
// CHECK: [[@LINE-3]]:11 | function/infix-operator/Swift | +(_:_:) | s:Fsoi1pFTSiSi_Si | Ref,Call | rel: 0
|
||||||
|
|
||||||
// Read of x + Write of y
|
// Read of x + Write of y
|
||||||
y = x + 1
|
y = x + 1
|
||||||
// CHECK: [[@LINE-1]]:1 | variable/Swift | y | s:v14swift_ide_test1ySi | Ref,Writ | rel: 0
|
// CHECK: [[@LINE-1]]:1 | variable/Swift | y | s:v14swift_ide_test1ySi | Ref,Writ | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:5 | variable/Swift | x | s:v14swift_ide_test1xSi | Ref,Read | rel: 0
|
// CHECK: [[@LINE-2]]:5 | variable/Swift | x | s:v14swift_ide_test1xSi | Ref,Read | rel: 0
|
||||||
// CHECK: [[@LINE-3]]:7 | infix-operator/Swift | +(_:_:) | s:Fsoi1pFTSiSi_Si | Ref,Call | rel: 0
|
// CHECK: [[@LINE-3]]:7 | function/infix-operator/Swift | +(_:_:) | s:Fsoi1pFTSiSi_Si | Ref,Call | rel: 0
|
||||||
|
|
||||||
// Read of y + Write of y
|
// Read of y + Write of y
|
||||||
y += x
|
y += x
|
||||||
// CHECK: [[@LINE-1]]:1 | variable/Swift | y | s:v14swift_ide_test1ySi | Ref,Read,Writ | rel: 0
|
// CHECK: [[@LINE-1]]:1 | variable/Swift | y | s:v14swift_ide_test1ySi | Ref,Read,Writ | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:3 | infix-operator/Swift | +=(_:_:) | s:Fsoi2peFTRSiSi_T_ | Ref,Call | rel: 0
|
// CHECK: [[@LINE-2]]:3 | function/infix-operator/Swift | +=(_:_:) | s:Fsoi2peFTRSiSi_T_ | Ref,Call | rel: 0
|
||||||
// CHECK: [[@LINE-3]]:6 | variable/Swift | x | s:v14swift_ide_test1xSi | Ref,Read | rel: 0
|
// CHECK: [[@LINE-3]]:6 | variable/Swift | x | s:v14swift_ide_test1xSi | Ref,Read | rel: 0
|
||||||
|
|
||||||
var z: Int {
|
var z: Int {
|
||||||
// CHECK: [[@LINE-1]]:5 | variable/Swift | z | s:v14swift_ide_test1zSi | Def | rel: 0
|
// CHECK: [[@LINE-1]]:5 | variable/Swift | z | s:v14swift_ide_test1zSi | Def | rel: 0
|
||||||
get {
|
get {
|
||||||
// CHECK: [[@LINE-1]]:3 | accessor(get)/Swift | getter:z | s:F14swift_ide_testg1zSi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:3 | function/acc-get/Swift | getter:z | s:F14swift_ide_testg1zSi | Def,RelChild,RelAcc | rel: 1
|
||||||
|
|
||||||
return y
|
return y
|
||||||
// CHECK: [[@LINE-1]]:12 | variable/Swift | y | s:v14swift_ide_test1ySi | Ref,Read | rel: 0
|
// CHECK: [[@LINE-1]]:12 | variable/Swift | y | s:v14swift_ide_test1ySi | Ref,Read | rel: 0
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
// CHECK: [[@LINE-1]]:3 | accessor(set)/Swift | setter:z | s:F14swift_ide_tests1zSi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:3 | function/acc-set/Swift | setter:z | s:F14swift_ide_tests1zSi | Def,RelChild,RelAcc | rel: 1
|
||||||
|
|
||||||
y = newValue
|
y = newValue
|
||||||
// CHECK: [[@LINE-1]]:5 | variable/Swift | y | s:v14swift_ide_test1ySi | Ref,Writ | rel: 0
|
// CHECK: [[@LINE-1]]:5 | variable/Swift | y | s:v14swift_ide_test1ySi | Ref,Writ | rel: 0
|
||||||
@@ -40,10 +40,10 @@ var z: Int {
|
|||||||
// Write + Read of z
|
// Write + Read of z
|
||||||
z = z + 1
|
z = z + 1
|
||||||
// CHECK: [[@LINE-1]]:1 | variable/Swift | z | s:v14swift_ide_test1zSi | Ref,Writ | rel: 0
|
// CHECK: [[@LINE-1]]:1 | variable/Swift | z | s:v14swift_ide_test1zSi | Ref,Writ | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:1 | accessor(set)/Swift | setter:z | s:F14swift_ide_tests1zSi | Ref,Call,Impl,RelCall | rel: 1
|
// CHECK: [[@LINE-2]]:1 | function/acc-set/Swift | setter:z | s:F14swift_ide_tests1zSi | Ref,Call,Impl,RelCall | rel: 1
|
||||||
// CHECK-NEXT: RelCall | z | s:v14swift_ide_test1zSi
|
// CHECK-NEXT: RelCall | z | s:v14swift_ide_test1zSi
|
||||||
// CHECK: [[@LINE-4]]:5 | variable/Swift | z | s:v14swift_ide_test1zSi | Ref,Read | rel: 0
|
// CHECK: [[@LINE-4]]:5 | variable/Swift | z | s:v14swift_ide_test1zSi | Ref,Read | rel: 0
|
||||||
// CHECK-NEXT: [[@LINE-5]]:5 | accessor(get)/Swift | getter:z | s:F14swift_ide_testg1zSi | Ref,Call,Impl,RelCall | rel: 1
|
// CHECK-NEXT: [[@LINE-5]]:5 | function/acc-get/Swift | getter:z | s:F14swift_ide_testg1zSi | Ref,Call,Impl,RelCall | rel: 1
|
||||||
|
|
||||||
// Call
|
// Call
|
||||||
func aCalledFunction() {}
|
func aCalledFunction() {}
|
||||||
@@ -72,29 +72,29 @@ struct AStruct {
|
|||||||
|
|
||||||
x += 1
|
x += 1
|
||||||
// CHECK: [[@LINE-1]]:5 | instance-property/Swift | x | s:vV14swift_ide_test7AStruct1xSi | Ref,Read,Writ | rel: 0
|
// CHECK: [[@LINE-1]]:5 | instance-property/Swift | x | s:vV14swift_ide_test7AStruct1xSi | Ref,Read,Writ | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:5 | accessor(get)/Swift | getter:x | s:FV14swift_ide_test7AStructg1xSi | Ref,Call,Impl,RelRec,RelCall | rel: 2
|
// CHECK: [[@LINE-2]]:5 | function/acc-get/Swift | getter:x | s:FV14swift_ide_test7AStructg1xSi | Ref,Call,Impl,RelRec,RelCall | rel: 2
|
||||||
// CHECK-NEXT: RelCall | x | s:vV14swift_ide_test7AStruct1xSi
|
// CHECK-NEXT: RelCall | x | s:vV14swift_ide_test7AStruct1xSi
|
||||||
// CHECK-NEXT: RelRec | AStruct | s:V14swift_ide_test7AStruct
|
// CHECK-NEXT: RelRec | AStruct | s:V14swift_ide_test7AStruct
|
||||||
// CHECK: [[@LINE-5]]:5 | accessor(set)/Swift | setter:x | s:FV14swift_ide_test7AStructs1xSi | Ref,Call,Impl,RelRec,RelCall | rel: 2
|
// CHECK: [[@LINE-5]]:5 | function/acc-set/Swift | setter:x | s:FV14swift_ide_test7AStructs1xSi | Ref,Call,Impl,RelRec,RelCall | rel: 2
|
||||||
// CHECK-NEXT: RelCall | x | s:vV14swift_ide_test7AStruct1xSi
|
// CHECK-NEXT: RelCall | x | s:vV14swift_ide_test7AStruct1xSi
|
||||||
// CHECK-NEXT: RelRec | AStruct | s:V14swift_ide_test7AStruct
|
// CHECK-NEXT: RelRec | AStruct | s:V14swift_ide_test7AStruct
|
||||||
// CHECK: [[@LINE-8]]:7 | infix-operator/Swift | +=(_:_:) | s:Fsoi2peFTRSiSi_T_ | Ref,Call,RelCall | rel: 1
|
// CHECK: [[@LINE-8]]:7 | function/infix-operator/Swift | +=(_:_:) | s:Fsoi2peFTRSiSi_T_ | Ref,Call,RelCall | rel: 1
|
||||||
// CHECK-NEXT: RelCall | aMethod() | s:FV14swift_ide_test7AStruct7aMethodFT_T_
|
// CHECK-NEXT: RelCall | aMethod() | s:FV14swift_ide_test7AStruct7aMethodFT_T_
|
||||||
}
|
}
|
||||||
|
|
||||||
// RelationChildOf, RelationAccessorOf
|
// RelationChildOf, RelationAccessorOf
|
||||||
subscript(index: Int) -> Int {
|
subscript(index: Int) -> Int {
|
||||||
// CHECK: [[@LINE-1]]:3 | subscript/Swift | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi | Def,RelChild | rel: 1
|
// CHECK: [[@LINE-1]]:3 | instance-property/subscript/Swift | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi | Def,RelChild | rel: 1
|
||||||
// CHECK-NEXT: RelChild | AStruct | s:V14swift_ide_test7AStruct
|
// CHECK-NEXT: RelChild | AStruct | s:V14swift_ide_test7AStruct
|
||||||
|
|
||||||
get {
|
get {
|
||||||
// CHECK: [[@LINE-1]]:5 | accessor(get)/Swift | getter:subscript(_:) | s:FV14swift_ide_test7AStructg9subscriptFSiSi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:5 | instance-method/acc-get/Swift | getter:subscript(_:) | s:FV14swift_ide_test7AStructg9subscriptFSiSi | Def,RelChild,RelAcc | rel: 1
|
||||||
// CHECK-NEXT: RelChild,RelAcc | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi
|
// CHECK-NEXT: RelChild,RelAcc | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi
|
||||||
|
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
// CHECK: [[@LINE-1]]:5 | accessor(set)/Swift | setter:subscript(_:) | s:FV14swift_ide_test7AStructs9subscriptFSiSi | Def,RelChild,RelAcc | rel: 1
|
// CHECK: [[@LINE-1]]:5 | instance-method/acc-set/Swift | setter:subscript(_:) | s:FV14swift_ide_test7AStructs9subscriptFSiSi | Def,RelChild,RelAcc | rel: 1
|
||||||
// CHECK-NEXT: RelChild,RelAcc | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi
|
// CHECK-NEXT: RelChild,RelAcc | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi
|
||||||
|
|
||||||
x = newValue
|
x = newValue
|
||||||
@@ -151,7 +151,7 @@ class ASubClass : AClass, AProtocol {
|
|||||||
// RelationExtendedBy
|
// RelationExtendedBy
|
||||||
// FIXME give extensions their own USR like ObjC?
|
// FIXME give extensions their own USR like ObjC?
|
||||||
extension AClass {
|
extension AClass {
|
||||||
// CHECK: [[@LINE-1]]:11 | extension(extClass)/Swift | AClass | s:C14swift_ide_test6AClass | Def | rel: 0
|
// CHECK: [[@LINE-1]]:11 | extension/ext-class/Swift | AClass | s:C14swift_ide_test6AClass | Def | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:11 | class/Swift | AClass | s:C14swift_ide_test6AClass | Ref,RelExt | rel: 1
|
// CHECK: [[@LINE-2]]:11 | class/Swift | AClass | s:C14swift_ide_test6AClass | Ref,RelExt | rel: 1
|
||||||
// CHECK-NEXT: RelExt | AClass | s:C14swift_ide_test6AClass
|
// CHECK-NEXT: RelExt | AClass | s:C14swift_ide_test6AClass
|
||||||
|
|
||||||
@@ -189,11 +189,11 @@ let otherInstance = AStruct(x: 1)
|
|||||||
|
|
||||||
let _ = otherInstance[0]
|
let _ = otherInstance[0]
|
||||||
// CHECK: [[@LINE-1]]:9 | variable/Swift | otherInstance | s:v14swift_ide_test13otherInstanceVS_7AStruct | Ref,Read | rel: 0
|
// CHECK: [[@LINE-1]]:9 | variable/Swift | otherInstance | s:v14swift_ide_test13otherInstanceVS_7AStruct | Ref,Read | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:22 | subscript/Swift | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi | Ref,Read | rel: 0
|
// CHECK: [[@LINE-2]]:22 | instance-property/subscript/Swift | subscript(_:) | s:iV14swift_ide_test7AStruct9subscriptFSiSi | Ref,Read | rel: 0
|
||||||
|
|
||||||
let _ = anInstance[0]
|
let _ = anInstance[0]
|
||||||
// CHECK: [[@LINE-1]]:9 | variable/Swift | anInstance | s:v14swift_ide_test10anInstanceCS_6AClass | Ref,Read | rel: 0
|
// CHECK: [[@LINE-1]]:9 | variable/Swift | anInstance | s:v14swift_ide_test10anInstanceCS_6AClass | Ref,Read | rel: 0
|
||||||
// CHECK: [[@LINE-2]]:19 | subscript/Swift | subscript(_:) | s:iC14swift_ide_test6AClass9subscriptFSiSi | Ref,Read | rel: 0
|
// CHECK: [[@LINE-2]]:19 | instance-property/subscript/Swift | subscript(_:) | s:iC14swift_ide_test6AClass9subscriptFSiSi | Ref,Read | rel: 0
|
||||||
|
|
||||||
let aSubInstance: AClass = ASubClass(x: 1)
|
let aSubInstance: AClass = ASubClass(x: 1)
|
||||||
// CHECK: [[@LINE-1]]:5 | variable/Swift | aSubInstance | s:v14swift_ide_test12aSubInstanceCS_6AClass | Def | rel: 0
|
// CHECK: [[@LINE-1]]:5 | variable/Swift | aSubInstance | s:v14swift_ide_test12aSubInstanceCS_6AClass | Def | rel: 0
|
||||||
|
|||||||
@@ -31,15 +31,8 @@ using namespace swift::index;
|
|||||||
static UIdent KindImportModuleClang("source.lang.swift.import.module.clang");
|
static UIdent KindImportModuleClang("source.lang.swift.import.module.clang");
|
||||||
static UIdent KindImportModuleSwift("source.lang.swift.import.module.swift");
|
static UIdent KindImportModuleSwift("source.lang.swift.import.module.swift");
|
||||||
|
|
||||||
static UIdent getUIDForDependencyKind(SymbolKind depKind) {
|
static UIdent getUIDForDependencyKind(bool isClangModule) {
|
||||||
switch (depKind) {
|
return isClangModule ? KindImportModuleClang : KindImportModuleSwift;
|
||||||
case SymbolKind::Module:
|
|
||||||
return KindImportModuleSwift;
|
|
||||||
case SymbolKind::ClangModule:
|
|
||||||
return KindImportModuleClang;
|
|
||||||
default:
|
|
||||||
return UIdent();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SKIndexDataConsumer : public IndexDataConsumer {
|
class SKIndexDataConsumer : public IndexDataConsumer {
|
||||||
@@ -61,14 +54,14 @@ private:
|
|||||||
return impl.recordHash(hash, isKnown);
|
return impl.recordHash(hash, isKnown);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool startDependency(SymbolKind kind, StringRef name, StringRef path,
|
bool startDependency(StringRef name, StringRef path, bool isClangModule,
|
||||||
bool isSystem, StringRef hash) override {
|
bool isSystem, StringRef hash) override {
|
||||||
auto kindUID = getUIDForDependencyKind(kind);
|
auto kindUID = getUIDForDependencyKind(isClangModule);
|
||||||
return impl.startDependency(kindUID, name, path, isSystem, hash);
|
return impl.startDependency(kindUID, name, path, isSystem, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool finishDependency(SymbolKind kind) override {
|
bool finishDependency(bool isClangModule) override {
|
||||||
return impl.finishDependency(getUIDForDependencyKind(kind));
|
return impl.finishDependency(getUIDForDependencyKind(isClangModule));
|
||||||
}
|
}
|
||||||
|
|
||||||
Action startSourceEntity(const IndexSymbol &symbol) override {
|
Action startSourceEntity(const IndexSymbol &symbol) override {
|
||||||
@@ -103,10 +96,9 @@ private:
|
|||||||
return Continue;
|
return Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool finishSourceEntity(SymbolKind kind, SymbolSubKindSet subKinds,
|
bool finishSourceEntity(SymbolInfo symInfo, SymbolRoleSet roles) override {
|
||||||
SymbolRoleSet roles) override {
|
|
||||||
bool isRef = roles & (unsigned)SymbolRole::Reference;
|
bool isRef = roles & (unsigned)SymbolRole::Reference;
|
||||||
auto UID = SwiftLangSupport::getUIDForSymbol(kind, subKinds, isRef);
|
auto UID = SwiftLangSupport::getUIDForSymbol(symInfo, isRef);
|
||||||
return impl.finishSourceEntity(UID);
|
return impl.finishSourceEntity(UID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,8 +108,7 @@ private:
|
|||||||
bool isRef = symbol.roles & (unsigned)SymbolRole::Reference;
|
bool isRef = symbol.roles & (unsigned)SymbolRole::Reference;
|
||||||
bool isImplicit = symbol.roles & (unsigned)SymbolRole::Implicit;
|
bool isImplicit = symbol.roles & (unsigned)SymbolRole::Implicit;
|
||||||
|
|
||||||
info.Kind = SwiftLangSupport::getUIDForSymbol(symbol.kind, symbol.subKinds,
|
info.Kind = SwiftLangSupport::getUIDForSymbol(symbol.symInfo, isRef);
|
||||||
isRef);
|
|
||||||
info.Name = isImplicit? "" : symbol.name;
|
info.Name = isImplicit? "" : symbol.name;
|
||||||
info.USR = symbol.USR;
|
info.USR = symbol.USR;
|
||||||
info.Group = symbol.group;
|
info.Group = symbol.group;
|
||||||
@@ -125,7 +116,7 @@ private:
|
|||||||
info.Column = symbol.column;
|
info.Column = symbol.column;
|
||||||
info.ReceiverUSR = symbol.getReceiverUSR();
|
info.ReceiverUSR = symbol.getReceiverUSR();
|
||||||
info.IsDynamic = symbol.roles & (unsigned)SymbolRole::Dynamic;
|
info.IsDynamic = symbol.roles & (unsigned)SymbolRole::Dynamic;
|
||||||
info.IsTestCandidate = symbol.subKinds & SymbolSubKind::UnitTest;
|
info.IsTestCandidate = symbol.symInfo.Properties & SymbolProperty::UnitTest;
|
||||||
std::vector<UIdent> uidAttrs;
|
std::vector<UIdent> uidAttrs;
|
||||||
if (!isRef) {
|
if (!isRef) {
|
||||||
uidAttrs =
|
uidAttrs =
|
||||||
@@ -140,13 +131,12 @@ private:
|
|||||||
EntityInfo info;
|
EntityInfo info;
|
||||||
bool isRef = (relation.roles & (unsigned)SymbolRole::Reference) ||
|
bool isRef = (relation.roles & (unsigned)SymbolRole::Reference) ||
|
||||||
(relation.roles & (unsigned)SymbolRole::RelationOverrideOf);
|
(relation.roles & (unsigned)SymbolRole::RelationOverrideOf);
|
||||||
info.Kind = SwiftLangSupport::getUIDForSymbol(relation.kind, relation.subKinds,
|
info.Kind = SwiftLangSupport::getUIDForSymbol(relation.symInfo, isRef);
|
||||||
isRef);
|
|
||||||
info.Name = relation.name;
|
info.Name = relation.name;
|
||||||
info.USR = relation.USR;
|
info.USR = relation.USR;
|
||||||
info.Group = relation.group;
|
info.Group = relation.group;
|
||||||
info.IsDynamic = relation.roles & (unsigned)SymbolRole::Dynamic;
|
info.IsDynamic = relation.roles & (unsigned)SymbolRole::Dynamic;
|
||||||
info.IsTestCandidate = relation.subKinds & SymbolSubKind::UnitTest;
|
info.IsTestCandidate = relation.symInfo.Properties & SymbolProperty::UnitTest;
|
||||||
std::vector<UIdent> uidAttrs;
|
std::vector<UIdent> uidAttrs;
|
||||||
if (!isRef) {
|
if (!isRef) {
|
||||||
uidAttrs =
|
uidAttrs =
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ using namespace swift;
|
|||||||
using namespace swift::ide;
|
using namespace swift::ide;
|
||||||
using swift::index::SymbolKind;
|
using swift::index::SymbolKind;
|
||||||
using swift::index::SymbolSubKind;
|
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::SymbolRole;
|
||||||
using swift::index::SymbolRoleSet;
|
using swift::index::SymbolRoleSet;
|
||||||
|
|
||||||
@@ -548,36 +550,50 @@ getUIDForRangeKind(swift::ide::RangeKind Kind) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UIdent SwiftLangSupport::getUIDForSymbol(SymbolKind kind, SymbolSubKindSet subKinds,
|
UIdent SwiftLangSupport::getUIDForSymbol(SymbolInfo sym, bool isRef) {
|
||||||
bool isRef) {
|
|
||||||
|
|
||||||
#define UID_FOR(CLASS) isRef ? KindRef##CLASS : KindDecl##CLASS;
|
#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) \
|
#define SIMPLE_CASE(KIND) \
|
||||||
case SymbolKind::KIND: \
|
case SymbolKind::KIND: \
|
||||||
return UID_FOR(KIND);
|
return UID_FOR(KIND);
|
||||||
|
|
||||||
switch (kind) {
|
switch (sym.Kind) {
|
||||||
SIMPLE_CASE(Enum)
|
SIMPLE_CASE(Enum)
|
||||||
SIMPLE_CASE(Struct)
|
SIMPLE_CASE(Struct)
|
||||||
SIMPLE_CASE(Class)
|
SIMPLE_CASE(Class)
|
||||||
SIMPLE_CASE(Protocol)
|
SIMPLE_CASE(Protocol)
|
||||||
SIMPLE_CASE(TypeAlias)
|
|
||||||
SIMPLE_CASE(AssociatedType)
|
|
||||||
SIMPLE_CASE(GenericTypeParam)
|
|
||||||
SIMPLE_CASE(Subscript)
|
|
||||||
SIMPLE_CASE(EnumElement)
|
|
||||||
SIMPLE_CASE(Constructor)
|
SIMPLE_CASE(Constructor)
|
||||||
SIMPLE_CASE(Destructor)
|
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:
|
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);
|
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:
|
case SymbolKind::Variable:
|
||||||
return UID_FOR(VarGlobal);
|
return UID_FOR(VarGlobal);
|
||||||
case SymbolKind::InstanceMethod:
|
case SymbolKind::InstanceMethod:
|
||||||
@@ -587,6 +603,8 @@ UIdent SwiftLangSupport::getUIDForSymbol(SymbolKind kind, SymbolSubKindSet subKi
|
|||||||
case SymbolKind::StaticMethod:
|
case SymbolKind::StaticMethod:
|
||||||
return UID_FOR(MethodStatic);
|
return UID_FOR(MethodStatic);
|
||||||
case SymbolKind::InstanceProperty:
|
case SymbolKind::InstanceProperty:
|
||||||
|
if (sym.SubKind == SymbolSubKind::SwiftSubscript)
|
||||||
|
return UID_FOR(Subscript);
|
||||||
return UID_FOR(VarInstance);
|
return UID_FOR(VarInstance);
|
||||||
case SymbolKind::ClassProperty:
|
case SymbolKind::ClassProperty:
|
||||||
return UID_FOR(VarClass);
|
return UID_FOR(VarClass);
|
||||||
@@ -595,32 +613,16 @@ UIdent SwiftLangSupport::getUIDForSymbol(SymbolKind kind, SymbolSubKindSet subKi
|
|||||||
|
|
||||||
case SymbolKind::Extension:
|
case SymbolKind::Extension:
|
||||||
assert(!isRef && "reference to extension decl?");
|
assert(!isRef && "reference to extension decl?");
|
||||||
SWIFT_FALLTHROUGH;
|
if (sym.SubKind == SymbolSubKind::SwiftExtensionOfStruct) {
|
||||||
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) {
|
|
||||||
return KindDeclExtensionStruct;
|
return KindDeclExtensionStruct;
|
||||||
} else if (subKinds & SymbolSubKind::ExtensionOfClass) {
|
} else if (sym.SubKind == SymbolSubKind::SwiftExtensionOfClass) {
|
||||||
return KindDeclExtensionClass;
|
return KindDeclExtensionClass;
|
||||||
} else if (subKinds & SymbolSubKind::ExtensionOfEnum) {
|
} else if (sym.SubKind == SymbolSubKind::SwiftExtensionOfEnum) {
|
||||||
return KindDeclExtensionEnum;
|
return KindDeclExtensionEnum;
|
||||||
} else if (subKinds & SymbolSubKind::ExtensionOfProtocol) {
|
} else if (sym.SubKind == SymbolSubKind::SwiftExtensionOfProtocol) {
|
||||||
return KindDeclExtensionProtocol;
|
return KindDeclExtensionProtocol;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
llvm_unreachable("missing sub kind");
|
llvm_unreachable("missing extension sub kind");
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -250,8 +250,7 @@ public:
|
|||||||
static SourceKit::UIdent getUIDForSyntaxStructureElementKind(
|
static SourceKit::UIdent getUIDForSyntaxStructureElementKind(
|
||||||
swift::ide::SyntaxStructureElementKind Kind);
|
swift::ide::SyntaxStructureElementKind Kind);
|
||||||
|
|
||||||
static SourceKit::UIdent getUIDForSymbol(swift::index::SymbolKind kind,
|
static SourceKit::UIdent getUIDForSymbol(swift::index::SymbolInfo sym,
|
||||||
swift::index::SymbolSubKindSet subKinds,
|
|
||||||
bool isRef);
|
bool isRef);
|
||||||
|
|
||||||
static SourceKit::UIdent getUIDForRangeKind(swift::ide::RangeKind Kind);
|
static SourceKit::UIdent getUIDForRangeKind(swift::ide::RangeKind Kind);
|
||||||
|
|||||||
@@ -2680,43 +2680,42 @@ namespace {
|
|||||||
raw_ostream &OS;
|
raw_ostream &OS;
|
||||||
bool firstSourceEntity = true;
|
bool firstSourceEntity = true;
|
||||||
|
|
||||||
void anchor() {}
|
void printSymbolInfo(SymbolInfo SymInfo) {
|
||||||
|
OS << getSymbolKindString(SymInfo.Kind);
|
||||||
void printSymbolKind(SymbolKind kind, SymbolSubKindSet subKinds) {
|
if (SymInfo.SubKind != SymbolSubKind::None)
|
||||||
OS << getSymbolKindString(kind);
|
OS << '/' << getSymbolSubKindString(SymInfo.SubKind);
|
||||||
if (subKinds) {
|
if (SymInfo.Properties) {
|
||||||
OS << '(';
|
OS << '(';
|
||||||
printSymbolSubKinds(subKinds, OS);
|
printSymbolProperties(SymInfo.Properties, OS);
|
||||||
OS << ')';
|
OS << ')';
|
||||||
}
|
}
|
||||||
// FIXME: add and use language enum
|
OS << '/' << getSymbolLanguageString(SymInfo.Lang);
|
||||||
OS << '/' << "Swift";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PrintIndexDataConsumer(raw_ostream &OS) : OS(OS) {}
|
PrintIndexDataConsumer(raw_ostream &OS) : OS(OS) {}
|
||||||
|
|
||||||
void failed(StringRef error) {}
|
void failed(StringRef error) override {}
|
||||||
|
|
||||||
bool recordHash(StringRef hash, bool isKnown) { return true; }
|
bool recordHash(StringRef hash, bool isKnown) override { return true; }
|
||||||
bool startDependency(SymbolKind kind, StringRef name, StringRef path,
|
bool startDependency(StringRef name, StringRef path, bool isClangModule,
|
||||||
bool isSystem, StringRef hash) {
|
bool isSystem, StringRef hash) override {
|
||||||
OS << getSymbolKindString(kind) << " | ";
|
OS << (isClangModule ? "clang-module" : "module") << " | ";
|
||||||
OS << (isSystem ? "system" : "user") << " | ";
|
OS << (isSystem ? "system" : "user") << " | ";
|
||||||
OS << name << " | " << path << "-" << hash << "\n";
|
OS << name << " | " << path << "-" << hash << "\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool finishDependency(SymbolKind kind) {
|
bool finishDependency(bool isClangModule) override {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Action startSourceEntity(const IndexSymbol &symbol) {
|
Action startSourceEntity(const IndexSymbol &symbol) override {
|
||||||
if (firstSourceEntity) {
|
if (firstSourceEntity) {
|
||||||
firstSourceEntity = false;
|
firstSourceEntity = false;
|
||||||
OS << "------------\n";
|
OS << "------------\n";
|
||||||
}
|
}
|
||||||
OS << symbol.line << ':' << symbol.column << " | ";
|
OS << symbol.line << ':' << symbol.column << " | ";
|
||||||
printSymbolKind(symbol.kind, symbol.subKinds);
|
printSymbolInfo(symbol.symInfo);
|
||||||
OS << " | " << symbol.name << " | " << symbol.USR << " | ";
|
OS << " | " << symbol.name << " | " << symbol.USR << " | ";
|
||||||
clang::index::printSymbolRoles(symbol.roles, OS);
|
clang::index::printSymbolRoles(symbol.roles, OS);
|
||||||
OS << " | rel: " << symbol.Relations.size() << "\n";
|
OS << " | rel: " << symbol.Relations.size() << "\n";
|
||||||
@@ -2728,12 +2727,11 @@ namespace {
|
|||||||
}
|
}
|
||||||
return Continue;
|
return Continue;
|
||||||
}
|
}
|
||||||
bool finishSourceEntity(SymbolKind kind, SymbolSubKindSet subKinds,
|
bool finishSourceEntity(SymbolInfo symInfo, SymbolRoleSet roles) override {
|
||||||
SymbolRoleSet roles) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void finish() {}
|
void finish() override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user