Skip to content

Commit ad269b0

Browse files
committed
[index] Move core indexing code out of SourceKit
Leaving only the SourceKit-specific code (e.g. UID generation) behind in SourceKit. rdar://problem/22348041
1 parent bfa5a1f commit ad269b0

File tree

12 files changed

+1256
-1095
lines changed

12 files changed

+1256
-1095
lines changed

include/swift/Index/Index.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===--- Index.h - Swift Indexing -------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_INDEX_INDEX_H
14+
#define SWIFT_INDEX_INDEX_H
15+
16+
#include "swift/Index/IndexDataConsumer.h"
17+
18+
namespace swift {
19+
class ModuleDecl;
20+
21+
namespace index {
22+
23+
void indexModule(ModuleDecl *module, StringRef hash, unsigned bufferID,
24+
IndexDataConsumer &consumer);
25+
26+
} // end namespace index
27+
} // end namespace swift
28+
29+
#endif // SWIFT_INDEX_INDEX_H
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===--- IndexDataConsumer.h - Consumer of indexing information -*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_INDEX_INDEXDATACONSUMER_H
14+
#define SWIFT_INDEX_INDEXDATACONSUMER_H
15+
16+
#include "swift/Index/IndexSymbol.h"
17+
18+
namespace swift {
19+
namespace index {
20+
21+
class IndexDataConsumer {
22+
virtual void anchor();
23+
24+
public:
25+
virtual ~IndexDataConsumer() {}
26+
27+
virtual void failed(StringRef error) = 0;
28+
virtual void warning(StringRef warning) {}
29+
virtual bool enableWarnings() { return false; }
30+
31+
virtual bool recordHash(StringRef hash, bool isKnown) = 0;
32+
virtual bool startDependency(SymbolKind kind, StringRef name, StringRef path,
33+
bool isSystem, StringRef hash) = 0;
34+
virtual bool finishDependency(SymbolKind kind) = 0;
35+
virtual bool startSourceEntity(const IndexSymbol &symbol) = 0;
36+
virtual bool recordRelatedEntity(const IndexSymbol &symbol) = 0;
37+
virtual bool finishSourceEntity(SymbolKind kind, SymbolSubKind subKind,
38+
bool isRef) = 0;
39+
};
40+
41+
} // end namespace index
42+
} // end namespace swift
43+
44+
#endif // SWIFT_INDEX_INDEXDATACONSUMER_H

tools/SourceKit/lib/SwiftLang/SwiftIndexing.h renamed to include/swift/Index/IndexSymbol.h

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- SwiftIndexing.h --------------------------------------------------===//
1+
//===--- IndexSymbol.h - Index symbol data types ----------------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,8 +10,16 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef LLVM_SOURCEKIT_LIB_SWIFTLANG_SWIFTINDEXING_H
14-
#define LLVM_SOURCEKIT_LIB_SWIFTLANG_SWIFTINDEXING_H
13+
#ifndef SWIFT_INDEX_INDEXSYMBOL_H
14+
#define SWIFT_INDEX_INDEXSYMBOL_H
15+
16+
#include "swift/Basic/LLVM.h"
17+
#include "llvm/ADT/SmallString.h"
18+
19+
namespace swift {
20+
class Decl;
21+
22+
namespace index {
1523

1624
enum class SymbolKind {
1725
Unknown,
@@ -71,4 +79,41 @@ enum class SymbolSubKind {
7179
ExtensionOfProtocol,
7280
};
7381

74-
#endif // LLVM_SOURCEKIT_LIB_SWIFTLANG_SWIFTINDEXING_H
82+
struct IndexSymbol {
83+
enum TypeKind { Base, FuncDecl, CallReference };
84+
TypeKind entityType = Base;
85+
86+
SymbolKind kind;
87+
SymbolSubKind subKind = SymbolSubKind::None;
88+
bool isRef;
89+
SmallString<32> name;
90+
SmallString<64> USR;
91+
SmallString<16> group;
92+
unsigned line = 0;
93+
unsigned column = 0;
94+
95+
IndexSymbol() = default;
96+
97+
protected:
98+
IndexSymbol(TypeKind TK) : entityType(TK) {}
99+
};
100+
101+
struct FuncDeclIndexSymbol : public IndexSymbol {
102+
bool IsTestCandidate = false;
103+
104+
FuncDeclIndexSymbol() : IndexSymbol(FuncDecl) {}
105+
};
106+
107+
struct CallRefIndexSymbol : public IndexSymbol {
108+
llvm::SmallString<64> ReceiverUSR;
109+
bool IsDynamic = false;
110+
111+
CallRefIndexSymbol() : IndexSymbol(CallReference) {}
112+
};
113+
114+
SymbolKind getSymbolKindForDecl(const Decl *D);
115+
116+
} // end namespace index
117+
} // end namespace swift
118+
119+
#endif // SWIFT_INDEX_INDEXSYMBOL_H

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_subdirectory(Basic)
44
add_subdirectory(ClangImporter)
55
add_subdirectory(Driver)
66
add_subdirectory(Frontend)
7+
add_subdirectory(Index)
78
add_subdirectory(IDE)
89
add_subdirectory(Immediate)
910
add_subdirectory(IRGen)

lib/Index/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_swift_library(swiftIndex
2+
Index.cpp
3+
IndexDataConsumer.cpp
4+
IndexSymbol.cpp
5+
LINK_LIBRARIES
6+
swiftAST)

0 commit comments

Comments
 (0)