Skip to content

[SourceKit] Delete old C++ NameMatcher #70389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ if(SWIFT_BUILD_SWIFT_SYNTAX)
message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled")
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
endif()
add_definitions(-DSWIFT_BUILD_SWIFT_SYNTAX)
endif()

if(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|.*-WITH-HOSTLIBS")
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsRefactoring.def
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

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

ERROR(extract_function_not_supported_swiftsyntax_missing, none, "Extract Function is not supported because sourcekitd was built without swift-syntax", ())

ERROR(invalid_location, none, "given location is not valid", ())

ERROR(arity_mismatch, none, "the given new name '%0' does not match the arity of the old name '%1'", (StringRef, StringRef))
Expand Down
20 changes: 0 additions & 20 deletions include/swift/IDE/IDEBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,4 @@ class BridgedResolvedLocVector {
void *getOpaqueValue() const;
};

#ifdef __cplusplus
extern "C" {
#endif

/// Entry point to run the NameMatcher written in swift-syntax.
///
/// - Parameters:
/// - sourceFilePtr: A pointer to an `ExportedSourceFile`, used to access the
/// syntax tree
/// - locations: Pointer to a buffer of `BridgedSourceLoc` that should be
/// resolved by the name matcher.
/// - locationsCount: Number of elements in `locations`.
/// - Returns: The opaque value of a `BridgedResolvedLocVector`.
void *swift_SwiftIDEUtilsBridging_runNameMatcher(const void *sourceFilePtr,
BridgedSourceLoc *locations,
size_t locationsCount);
#ifdef __cplusplus
}
#endif

#endif
80 changes: 13 additions & 67 deletions include/swift/IDE/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,73 +307,6 @@ struct CallingParent {
CallExpr *Call;
};


/// Finds the parse-only AST nodes and corresponding name and param/argument
/// label ranges for a given list of input name start locations
///
/// Resolved locations also indicate the nature of the matched occurrence (e.g.
/// whether it is within active/inactive code, or a selector or string literal).
class NameMatcher: public ASTWalker {
SourceFile &SrcFile;
std::vector<SourceLoc> LocsToResolve;
std::vector<ResolvedLoc> ResolvedLocs;
ArrayRef<Token> TokensToCheck;

/// The \c ArgumentList of a parent \c CustomAttr (if one exists) and
/// the \c SourceLoc of the type name it applies to.
llvm::Optional<Located<ArgumentList *>> CustomAttrArgList;
unsigned InactiveConfigRegionNestings = 0;
unsigned SelectorNestings = 0;

/// The stack of parent CallExprs and the innermost expression they apply to.
std::vector<CallingParent> ParentCalls;

SourceManager &getSourceMgr() const;

SourceLoc nextLoc() const;
bool isDone() const { return LocsToResolve.empty(); };
bool isActive() const { return !InactiveConfigRegionNestings; };
bool isInSelector() const { return SelectorNestings; };
bool checkComments();
void skipLocsBefore(SourceLoc Start);
bool shouldSkip(Expr *E);
bool shouldSkip(SourceRange Range);
bool shouldSkip(CharSourceRange Range);
bool tryResolve(ASTWalker::ParentTy Node, SourceLoc NameLoc);
bool tryResolve(ASTWalker::ParentTy Node, DeclNameLoc NameLoc,
ArgumentList *Args);
bool tryResolve(ASTWalker::ParentTy Node, SourceLoc NameLoc,
LabelRangeType RangeType, ArrayRef<CharSourceRange> LabelLocs,
llvm::Optional<unsigned> FirstTrailingLabel);
bool handleCustomAttrs(Decl *D);
ArgumentList *getApplicableArgsFor(Expr* E);

MacroWalking getMacroWalkingBehavior() const override {
return MacroWalking::Arguments;
}

PreWalkResult<Expr *> walkToExprPre(Expr *E) override;
PostWalkResult<Expr *> walkToExprPost(Expr *E) override;
PreWalkAction walkToDeclPre(Decl *D) override;
PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override;
PreWalkAction walkToTypeReprPre(TypeRepr *T) override;
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override;
bool shouldWalkIntoGenericParams() override { return true; }
bool shouldWalkIntoUncheckedMacroDefinitions() override { return true; }

PreWalkResult<ArgumentList *>
walkToArgumentListPre(ArgumentList *ArgList) override;

// FIXME: Remove this
bool shouldWalkAccessorsTheOldWay() override { return true; }

public:
explicit NameMatcher(SourceFile &SrcFile) : SrcFile(SrcFile) { }
std::vector<ResolvedLoc> resolve(ArrayRef<SourceLoc> Locs,
ArrayRef<Token> Tokens);
ResolvedLoc resolve(SourceLoc Loc);
};

enum class RangeKind : int8_t {
Invalid = -1,
SingleExpression,
Expand Down Expand Up @@ -715,6 +648,19 @@ bool isDynamicRef(Expr *Base, ValueDecl *D, llvm::function_ref<Type(Expr *)> get
void getReceiverType(Expr *Base,
SmallVectorImpl<NominalTypeDecl *> &Types);

#if SWIFT_BUILD_SWIFT_SYNTAX
/// Entry point to run the NameMatcher written in swift-syntax.
///
/// - Parameters:
/// - sourceFile: The source file from which to load the SwiftSyntax tree
/// - locations: The locations to resolve
/// - Returns: A list of `ResolvedLoc` that have been resolved. This list might
/// be shorteder than `locations` if some locations could not be resolved and
/// the resolved locations might be in a different order than `locations`.
std::vector<ResolvedLoc> runNameMatcher(const SourceFile &sourceFile,
ArrayRef<SourceLoc> locations);
#endif

} // namespace ide
} // namespace swift

Expand Down
7 changes: 0 additions & 7 deletions lib/AST/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@ target_link_libraries(swiftAST INTERFACE
clangAPINotes
clangBasic)

if(SWIFT_BUILD_SWIFT_SYNTAX)
target_compile_definitions(swiftAST
PRIVATE
SWIFT_BUILD_SWIFT_SYNTAX
)
endif()

target_link_libraries(swiftAST
PUBLIC swiftBasic
PRIVATE swiftMarkup)
Expand Down
7 changes: 0 additions & 7 deletions lib/DriverTool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ if(NOT SWIFT_BUILT_STANDALONE)
add_dependencies(swiftDriverTool clang-resource-headers)
endif()

if (SWIFT_BUILD_SWIFT_SYNTAX)
target_compile_definitions(swiftDriverTool
PRIVATE
SWIFT_BUILD_SWIFT_SYNTAX
)
endif()

set_swift_llvm_is_available(swiftDriverTool)

set(LLVM_TARGET_DEFINITIONS SwiftCacheToolOptions.td)
Expand Down
7 changes: 0 additions & 7 deletions lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,3 @@ target_link_libraries(swiftFrontend PRIVATE
swiftSymbolGraphGen)

set_swift_llvm_is_available(swiftFrontend)

if (SWIFT_BUILD_SWIFT_SYNTAX)
target_compile_definitions(swiftFrontend
PRIVATE
SWIFT_BUILD_SWIFT_SYNTAX
)
endif()
6 changes: 6 additions & 0 deletions lib/IDE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ target_link_libraries(swiftIDE PRIVATE
swiftParse
swiftSema)

if (SWIFT_BUILD_SWIFT_SYNTAX)
target_link_libraries(swiftIDE PRIVATE
swiftIDEUtilsBridging
)
endif()

set_swift_llvm_is_available(swiftIDE)
Loading