Skip to content

Commit 41e4e9b

Browse files
committed
Merge pull request #2188 from benlangmuir/move-index-ast-walker-out-of-sourcekit
2 parents 25f7632 + d817555 commit 41e4e9b

File tree

13 files changed

+1494
-915
lines changed

13 files changed

+1494
-915
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

include/swift/Index/IndexSymbol.h

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//===--- IndexSymbol.h - Index symbol data types ----------------*- 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_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 {
23+
24+
enum class SymbolKind {
25+
Unknown,
26+
27+
Module,
28+
ClangModule, // FIXME: collapse into Module and use a separate Language field.
29+
SourceFile,
30+
31+
Enum,
32+
Struct,
33+
Class,
34+
Protocol,
35+
Extension,
36+
37+
TypeAlias,
38+
AssociatedType,
39+
GenericTypeParam,
40+
41+
Function,
42+
PrefixOperator,
43+
PostfixOperator,
44+
InfixOperator,
45+
46+
LocalVariable,
47+
GlobalVariable,
48+
ParamVariable,
49+
50+
Accessor,
51+
Subscript,
52+
EnumElement,
53+
54+
InstanceMethod,
55+
ClassMethod,
56+
StaticMethod,
57+
InstanceProperty,
58+
ClassProperty,
59+
StaticProperty,
60+
61+
Constructor,
62+
Destructor,
63+
};
64+
65+
enum class SymbolSubKind {
66+
None,
67+
68+
AccessorGetter,
69+
AccessorSetter,
70+
AccessorWillSet,
71+
AccessorDidSet,
72+
AccessorMaterializeForSet,
73+
AccessorAddressor,
74+
AccessorMutableAddressor,
75+
76+
ExtensionOfStruct,
77+
ExtensionOfClass,
78+
ExtensionOfEnum,
79+
ExtensionOfProtocol,
80+
};
81+
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)