Skip to content

Commit 0b31642

Browse files
authored
Merge pull request swiftlang#36547 from bnbarham/include-init
[SourceKit/CursorInfo] Add constructor to call results
2 parents 46f167b + 3ea9bed commit 0b31642

File tree

21 files changed

+836
-858
lines changed

21 files changed

+836
-858
lines changed

include/swift/AST/FileUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class FileUnit : public DeclContext {
166166
return None;
167167
}
168168

169-
virtual void collectAllGroups(std::vector<StringRef> &Names) const {}
169+
virtual void collectAllGroups(SmallVectorImpl<StringRef> &Names) const {}
170170

171171
/// Returns an implementation-defined "discriminator" for \p D, which
172172
/// distinguishes \p D from other declarations in the same module with the

include/swift/IDE/ModuleInterfacePrinting.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ enum class ModuleTraversal : unsigned {
4242
/// Options used to describe the traversal of a module for printing.
4343
using ModuleTraversalOptions = OptionSet<ModuleTraversal>;
4444

45-
ArrayRef<StringRef> collectModuleGroups(ModuleDecl *M,
46-
std::vector<StringRef> &Scratch);
45+
void collectModuleGroups(ModuleDecl *M, SmallVectorImpl<StringRef> &Into);
4746

4847
Optional<StringRef>
4948
findGroupNameForUSR(ModuleDecl *M, StringRef USR);

include/swift/IDE/Refactoring.h

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ enum class RenameAvailableKind {
8181
Unavailable_decl_from_clang,
8282
};
8383

84-
struct RenameAvailabiliyInfo {
84+
struct RenameAvailabilityInfo {
8585
RefactoringKind Kind;
8686
RenameAvailableKind AvailableKind;
87-
RenameAvailabiliyInfo(RefactoringKind Kind, RenameAvailableKind AvailableKind) :
88-
Kind(Kind), AvailableKind(AvailableKind) {}
89-
RenameAvailabiliyInfo(RefactoringKind Kind) :
90-
RenameAvailabiliyInfo(Kind, RenameAvailableKind::Available) {}
87+
RenameAvailabilityInfo(RefactoringKind Kind,
88+
RenameAvailableKind AvailableKind)
89+
: Kind(Kind), AvailableKind(AvailableKind) {}
90+
RenameAvailabilityInfo(RefactoringKind Kind)
91+
: RenameAvailabilityInfo(Kind, RenameAvailableKind::Available) {}
9192
};
9293

9394
class FindRenameRangesConsumer {
@@ -130,17 +131,14 @@ int findLocalRenameRanges(SourceFile *SF, RangeConfig Range,
130131
FindRenameRangesConsumer &RenameConsumer,
131132
DiagnosticConsumer &DiagConsumer);
132133

133-
ArrayRef<RefactoringKind>
134-
collectAvailableRefactorings(SourceFile *SF, RangeConfig Range,
135-
bool &RangeStartMayNeedRename,
136-
std::vector<RefactoringKind> &Scratch,
137-
llvm::ArrayRef<DiagnosticConsumer*> DiagConsumers);
134+
void collectAvailableRefactorings(
135+
SourceFile *SF, RangeConfig Range, bool &RangeStartMayNeedRename,
136+
llvm::SmallVectorImpl<RefactoringKind> &Kinds,
137+
llvm::ArrayRef<DiagnosticConsumer *> DiagConsumers);
138138

139-
ArrayRef<RefactoringKind>
140-
collectAvailableRefactorings(SourceFile *SF,
141-
const ResolvedCursorInfo &CursorInfo,
142-
std::vector<RefactoringKind> &Scratch,
143-
bool ExcludeRename);
139+
void collectAvailableRefactorings(const ResolvedCursorInfo &CursorInfo,
140+
llvm::SmallVectorImpl<RefactoringKind> &Kinds,
141+
bool ExcludeRename);
144142

145143
/// Stores information about the reference that rename availability is being
146144
/// queried on.
@@ -150,10 +148,9 @@ struct RenameRefInfo {
150148
bool IsArgLabel; ///< Whether Loc is on an arg label, rather than base name.
151149
};
152150

153-
ArrayRef<RenameAvailabiliyInfo>
154-
collectRenameAvailabilityInfo(const ValueDecl *VD,
155-
Optional<RenameRefInfo> RefInfo,
156-
std::vector<RenameAvailabiliyInfo> &Scratch);
151+
void collectRenameAvailabilityInfo(
152+
const ValueDecl *VD, Optional<RenameRefInfo> RefInfo,
153+
llvm::SmallVectorImpl<RenameAvailabilityInfo> &Infos);
157154

158155
} // namespace ide
159156
} // namespace swift

include/swift/IDE/Utils.h

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ enum class CursorInfoKind {
152152

153153
struct ResolvedCursorInfo {
154154
CursorInfoKind Kind = CursorInfoKind::Invalid;
155-
SourceFile *SF;
155+
SourceFile *SF = nullptr;
156156
SourceLoc Loc;
157157
ValueDecl *ValueD = nullptr;
158158
TypeDecl *CtorTyRef = nullptr;
@@ -173,6 +173,8 @@ struct ResolvedCursorInfo {
173173
ResolvedCursorInfo() = default;
174174
ResolvedCursorInfo(SourceFile *SF) : SF(SF) {}
175175

176+
ValueDecl *typeOrValue() { return CtorTyRef ? CtorTyRef : ValueD; }
177+
176178
friend bool operator==(const ResolvedCursorInfo &lhs,
177179
const ResolvedCursorInfo &rhs) {
178180
return lhs.SF == rhs.SF &&
@@ -427,43 +429,6 @@ class DeclNameViewer {
427429
bool isFunction() const { return HasParen; }
428430
};
429431

430-
/// This provide a utility for writing to an underlying string buffer multiple
431-
/// string pieces and retrieve them later when the underlying buffer is stable.
432-
class DelayedStringRetriever : public raw_ostream {
433-
SmallVectorImpl<char> &OS;
434-
llvm::raw_svector_ostream Underlying;
435-
SmallVector<std::pair<unsigned, unsigned>, 4> StartEnds;
436-
unsigned CurrentStart;
437-
438-
public:
439-
explicit DelayedStringRetriever(SmallVectorImpl<char> &OS) : OS(OS),
440-
Underlying(OS) {}
441-
void startPiece() {
442-
CurrentStart = OS.size();
443-
}
444-
void endPiece() {
445-
StartEnds.emplace_back(CurrentStart, OS.size());
446-
}
447-
void write_impl(const char *ptr, size_t size) override {
448-
Underlying.write(ptr, size);
449-
}
450-
uint64_t current_pos() const override {
451-
return Underlying.tell();
452-
}
453-
size_t preferred_buffer_size() const override {
454-
return 0;
455-
}
456-
void retrieve(llvm::function_ref<void(StringRef)> F) const {
457-
for (auto P : StartEnds) {
458-
F(StringRef(OS.begin() + P.first, P.second - P.first));
459-
}
460-
}
461-
StringRef operator[](unsigned I) const {
462-
auto P = StartEnds[I];
463-
return StringRef(OS.begin() + P.first, P.second - P.first);
464-
}
465-
};
466-
467432
enum class RegionType {
468433
Unmatched,
469434
Mismatch,

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ class SerializedASTFile final : public LoadedFile {
394394

395395
Optional<BasicDeclLocs> getBasicLocsForDecl(const Decl *D) const override;
396396

397-
void collectAllGroups(std::vector<StringRef> &Names) const override;
397+
void collectAllGroups(SmallVectorImpl<StringRef> &Names) const override;
398398

399399
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;
400400

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,13 @@ static void adjustPrintOptions(PrintOptions &AdjustedOptions) {
202202
AdjustedOptions.VarInitializers = false;
203203
}
204204

205-
ArrayRef<StringRef>
206-
swift::ide::collectModuleGroups(ModuleDecl *M, std::vector<StringRef> &Scratch) {
205+
void swift::ide::collectModuleGroups(ModuleDecl *M,
206+
SmallVectorImpl<StringRef> &Into) {
207207
for (auto File : M->getFiles()) {
208-
File->collectAllGroups(Scratch);
208+
File->collectAllGroups(Into);
209209
}
210-
std::sort(Scratch.begin(), Scratch.end(), [](StringRef L, StringRef R) {
211-
return L.compare_lower(R) < 0;
212-
});
213-
return llvm::makeArrayRef(Scratch);
210+
std::sort(Into.begin(), Into.end(),
211+
[](StringRef L, StringRef R) { return L.compare_lower(R) < 0; });
214212
}
215213

216214
/// Determine whether the given extension has a Clang node that

0 commit comments

Comments
 (0)