Skip to content

Commit 4de3833

Browse files
authored
Merge pull request #70389 from ahoppen/ahoppen/delete-old-namematcher
[SourceKit] Delete old C++ `NameMatcher`
2 parents 55f9057 + 72d38e9 commit 4de3833

File tree

18 files changed

+98
-778
lines changed

18 files changed

+98
-778
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ if(SWIFT_BUILD_SWIFT_SYNTAX)
872872
message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled")
873873
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
874874
endif()
875+
add_definitions(-DSWIFT_BUILD_SWIFT_SYNTAX)
875876
endif()
876877

877878
if(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|.*-WITH-HOSTLIBS")

include/swift/AST/DiagnosticsRefactoring.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
ERROR(invalid_name, none, "'%0' is not a valid name", (StringRef))
2828

29+
ERROR(extract_function_not_supported_swiftsyntax_missing, none, "Extract Function is not supported because sourcekitd was built without swift-syntax", ())
30+
2931
ERROR(invalid_location, none, "given location is not valid", ())
3032

3133
ERROR(arity_mismatch, none, "the given new name '%0' does not match the arity of the old name '%1'", (StringRef, StringRef))

include/swift/IDE/IDEBridging.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,4 @@ class BridgedResolvedLocVector {
160160
void *getOpaqueValue() const;
161161
};
162162

163-
#ifdef __cplusplus
164-
extern "C" {
165-
#endif
166-
167-
/// Entry point to run the NameMatcher written in swift-syntax.
168-
///
169-
/// - Parameters:
170-
/// - sourceFilePtr: A pointer to an `ExportedSourceFile`, used to access the
171-
/// syntax tree
172-
/// - locations: Pointer to a buffer of `BridgedSourceLoc` that should be
173-
/// resolved by the name matcher.
174-
/// - locationsCount: Number of elements in `locations`.
175-
/// - Returns: The opaque value of a `BridgedResolvedLocVector`.
176-
void *swift_SwiftIDEUtilsBridging_runNameMatcher(const void *sourceFilePtr,
177-
BridgedSourceLoc *locations,
178-
size_t locationsCount);
179-
#ifdef __cplusplus
180-
}
181-
#endif
182-
183163
#endif

include/swift/IDE/Utils.h

Lines changed: 13 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -307,73 +307,6 @@ struct CallingParent {
307307
CallExpr *Call;
308308
};
309309

310-
311-
/// Finds the parse-only AST nodes and corresponding name and param/argument
312-
/// label ranges for a given list of input name start locations
313-
///
314-
/// Resolved locations also indicate the nature of the matched occurrence (e.g.
315-
/// whether it is within active/inactive code, or a selector or string literal).
316-
class NameMatcher: public ASTWalker {
317-
SourceFile &SrcFile;
318-
std::vector<SourceLoc> LocsToResolve;
319-
std::vector<ResolvedLoc> ResolvedLocs;
320-
ArrayRef<Token> TokensToCheck;
321-
322-
/// The \c ArgumentList of a parent \c CustomAttr (if one exists) and
323-
/// the \c SourceLoc of the type name it applies to.
324-
llvm::Optional<Located<ArgumentList *>> CustomAttrArgList;
325-
unsigned InactiveConfigRegionNestings = 0;
326-
unsigned SelectorNestings = 0;
327-
328-
/// The stack of parent CallExprs and the innermost expression they apply to.
329-
std::vector<CallingParent> ParentCalls;
330-
331-
SourceManager &getSourceMgr() const;
332-
333-
SourceLoc nextLoc() const;
334-
bool isDone() const { return LocsToResolve.empty(); };
335-
bool isActive() const { return !InactiveConfigRegionNestings; };
336-
bool isInSelector() const { return SelectorNestings; };
337-
bool checkComments();
338-
void skipLocsBefore(SourceLoc Start);
339-
bool shouldSkip(Expr *E);
340-
bool shouldSkip(SourceRange Range);
341-
bool shouldSkip(CharSourceRange Range);
342-
bool tryResolve(ASTWalker::ParentTy Node, SourceLoc NameLoc);
343-
bool tryResolve(ASTWalker::ParentTy Node, DeclNameLoc NameLoc,
344-
ArgumentList *Args);
345-
bool tryResolve(ASTWalker::ParentTy Node, SourceLoc NameLoc,
346-
LabelRangeType RangeType, ArrayRef<CharSourceRange> LabelLocs,
347-
llvm::Optional<unsigned> FirstTrailingLabel);
348-
bool handleCustomAttrs(Decl *D);
349-
ArgumentList *getApplicableArgsFor(Expr* E);
350-
351-
MacroWalking getMacroWalkingBehavior() const override {
352-
return MacroWalking::Arguments;
353-
}
354-
355-
PreWalkResult<Expr *> walkToExprPre(Expr *E) override;
356-
PostWalkResult<Expr *> walkToExprPost(Expr *E) override;
357-
PreWalkAction walkToDeclPre(Decl *D) override;
358-
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override;
359-
PreWalkAction walkToTypeReprPre(TypeRepr *T) override;
360-
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override;
361-
bool shouldWalkIntoGenericParams() override { return true; }
362-
bool shouldWalkIntoUncheckedMacroDefinitions() override { return true; }
363-
364-
PreWalkResult<ArgumentList *>
365-
walkToArgumentListPre(ArgumentList *ArgList) override;
366-
367-
// FIXME: Remove this
368-
bool shouldWalkAccessorsTheOldWay() override { return true; }
369-
370-
public:
371-
explicit NameMatcher(SourceFile &SrcFile) : SrcFile(SrcFile) { }
372-
std::vector<ResolvedLoc> resolve(ArrayRef<SourceLoc> Locs,
373-
ArrayRef<Token> Tokens);
374-
ResolvedLoc resolve(SourceLoc Loc);
375-
};
376-
377310
enum class RangeKind : int8_t {
378311
Invalid = -1,
379312
SingleExpression,
@@ -715,6 +648,19 @@ bool isDynamicRef(Expr *Base, ValueDecl *D, llvm::function_ref<Type(Expr *)> get
715648
void getReceiverType(Expr *Base,
716649
SmallVectorImpl<NominalTypeDecl *> &Types);
717650

651+
#if SWIFT_BUILD_SWIFT_SYNTAX
652+
/// Entry point to run the NameMatcher written in swift-syntax.
653+
///
654+
/// - Parameters:
655+
/// - sourceFile: The source file from which to load the SwiftSyntax tree
656+
/// - locations: The locations to resolve
657+
/// - Returns: A list of `ResolvedLoc` that have been resolved. This list might
658+
/// be shorteder than `locations` if some locations could not be resolved and
659+
/// the resolved locations might be in a different order than `locations`.
660+
std::vector<ResolvedLoc> runNameMatcher(const SourceFile &sourceFile,
661+
ArrayRef<SourceLoc> locations);
662+
#endif
663+
718664
} // namespace ide
719665
} // namespace swift
720666

lib/AST/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ target_link_libraries(swiftAST INTERFACE
154154
clangAPINotes
155155
clangBasic)
156156

157-
if(SWIFT_BUILD_SWIFT_SYNTAX)
158-
target_compile_definitions(swiftAST
159-
PRIVATE
160-
SWIFT_BUILD_SWIFT_SYNTAX
161-
)
162-
endif()
163-
164157
target_link_libraries(swiftAST
165158
PUBLIC swiftBasic
166159
PRIVATE swiftMarkup)

lib/DriverTool/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ if(NOT SWIFT_BUILT_STANDALONE)
3535
add_dependencies(swiftDriverTool clang-resource-headers)
3636
endif()
3737

38-
if (SWIFT_BUILD_SWIFT_SYNTAX)
39-
target_compile_definitions(swiftDriverTool
40-
PRIVATE
41-
SWIFT_BUILD_SWIFT_SYNTAX
42-
)
43-
endif()
44-
4538
set_swift_llvm_is_available(swiftDriverTool)
4639

4740
set(LLVM_TARGET_DEFINITIONS SwiftCacheToolOptions.td)

lib/Frontend/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,3 @@ target_link_libraries(swiftFrontend PRIVATE
3838
swiftSymbolGraphGen)
3939

4040
set_swift_llvm_is_available(swiftFrontend)
41-
42-
if (SWIFT_BUILD_SWIFT_SYNTAX)
43-
target_compile_definitions(swiftFrontend
44-
PRIVATE
45-
SWIFT_BUILD_SWIFT_SYNTAX
46-
)
47-
endif()

lib/IDE/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ target_link_libraries(swiftIDE PRIVATE
4646
swiftParse
4747
swiftSema)
4848

49+
if (SWIFT_BUILD_SWIFT_SYNTAX)
50+
target_link_libraries(swiftIDE PRIVATE
51+
swiftIDEUtilsBridging
52+
)
53+
endif()
54+
4955
set_swift_llvm_is_available(swiftIDE)

0 commit comments

Comments
 (0)