Skip to content

Revert "migrator: handle AppKit protocol migrations. rdar://42480588" #18280

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 1 commit into from
Jul 27, 2018
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
98 changes: 1 addition & 97 deletions lib/Migrator/APIDiffMigratorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {

std::vector<ConversionFunctionInfo> HelperFuncInfo;
SourceLoc FileEndLoc;
llvm::StringSet<> OverridingRemoveNames;

/// For a given expression, check whether the type of this expression is
/// name alias type, and the name alias type is known to change to raw
Expand All @@ -386,8 +385,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
APIDiffMigratorPass(EditorAdapter &Editor, SourceFile *SF,
const MigratorOptions &Opts):
ASTMigratorPass(Editor, SF, Opts), DiffStore(Diags),
FileEndLoc(SM.getRangeForBuffer(BufferID).getEnd()),
OverridingRemoveNames(funcNamesForOverrideRemoval()) {}
FileEndLoc(SM.getRangeForBuffer(BufferID).getEnd()) {}

~APIDiffMigratorPass() {
Editor.disableCache();
Expand Down Expand Up @@ -1292,92 +1290,6 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
}
}

llvm::StringSet<> funcNamesForOverrideRemoval() {
llvm::StringSet<> Results;
Results.insert("c:objc(cs)NSObject(im)application:delegateHandlesKey:");
Results.insert("c:objc(cs)NSObject(im)changeColor:");
Results.insert("c:objc(cs)NSObject(im)controlTextDidBeginEditing:");
Results.insert("c:objc(cs)NSObject(im)controlTextDidEndEditing:");
Results.insert("c:objc(cs)NSObject(im)controlTextDidChange:");
Results.insert("c:objc(cs)NSObject(im)changeFont:");
Results.insert("c:objc(cs)NSObject(im)validModesForFontPanel:");
Results.insert("c:objc(cs)NSObject(im)discardEditing");
Results.insert("c:objc(cs)NSObject(im)commitEditing");
Results.insert("c:objc(cs)NSObject(im)commitEditingWithDelegate:didCommitSelector:contextInfo:");
Results.insert("c:objc(cs)NSObject(im)commitEditingAndReturnError:");
Results.insert("c:objc(cs)NSObject(im)objectDidBeginEditing:");
Results.insert("c:objc(cs)NSObject(im)objectDidEndEditing:");
Results.insert("c:objc(cs)NSObject(im)validateMenuItem:");
Results.insert("c:objc(cs)NSObject(im)pasteboard:provideDataForType:");
Results.insert("c:objc(cs)NSObject(im)pasteboardChangedOwner:");
Results.insert("c:objc(cs)NSObject(im)validateToolbarItem:");
Results.insert("c:objc(cs)NSObject(im)layer:shouldInheritContentsScale:fromWindow:");
Results.insert("c:objc(cs)NSObject(im)view:stringForToolTip:point:userData:");
return Results;
}

SourceLoc shouldRemoveOverride(AbstractFunctionDecl *AFD) {
if (AFD->getKind() != DeclKind::Func)
return SourceLoc();
SourceLoc OverrideLoc;

// Get the location of override keyword.
if (auto *Override = AFD->getAttrs().getAttribute<OverrideAttr>()) {
if (Override->getRange().isValid()) {
OverrideLoc = Override->getLocation();
}
}
if (OverrideLoc.isInvalid())
return SourceLoc();
auto *OD = AFD->getOverriddenDecl();
llvm::SmallString<64> Buffer;
llvm::raw_svector_ostream OS(Buffer);
if (swift::ide::printDeclUSR(OD, OS))
return SourceLoc();
return OverridingRemoveNames.find(OS.str()) == OverridingRemoveNames.end() ?
SourceLoc() : OverrideLoc;
}

struct SuperRemoval: public ASTWalker {
EditorAdapter &Editor;
llvm::StringSet<> &USRs;
SuperRemoval(EditorAdapter &Editor, llvm::StringSet<> &USRs):
Editor(Editor), USRs(USRs) {}
bool isSuperExpr(Expr *E) {
if (E->isImplicit())
return false;
// Check if the expression is super.foo().
if (auto *CE = dyn_cast<CallExpr>(E)) {
if (auto *DSC = dyn_cast<DotSyntaxCallExpr>(CE->getFn())) {
if (DSC->getBase()->getKind() != ExprKind::SuperRef)
return false;
llvm::SmallString<64> Buffer;
llvm::raw_svector_ostream OS(Buffer);
auto *RD = DSC->getFn()->getReferencedDecl().getDecl();
if (swift::ide::printDeclUSR(RD, OS))
return false;
return USRs.find(OS.str()) != USRs.end();
}
}
// We should handle try super.foo() too.
if (auto *TE = dyn_cast<AnyTryExpr>(E)) {
return isSuperExpr(TE->getSubExpr());
}
return false;
}
std::pair<bool, Stmt*> walkToStmtPre(Stmt *S) override {
if (auto *BS = dyn_cast<BraceStmt>(S)) {
for(auto Ele: BS->getElements()) {
if (Ele.is<Expr*>() && isSuperExpr(Ele.get<Expr*>())) {
Editor.remove(Ele.getSourceRange());
}
}
}
// We only handle top-level expressions, so avoid visiting further.
return {false, S};
}
};

bool walkToDeclPre(Decl *D, CharSourceRange Range) override {
if (D->isImplicit())
return true;
Expand All @@ -1393,14 +1305,6 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
handleLocalParameterBridge(AFD, DiffItem);
}
}
auto OverrideLoc = shouldRemoveOverride(AFD);
if (OverrideLoc.isValid()) {
// Remove override keyword.
Editor.remove(OverrideLoc);
// Remove super-dot call.
SuperRemoval Removal(Editor, OverridingRemoveNames);
D->walk(Removal);
}
}
return true;
}
Expand Down
126 changes: 0 additions & 126 deletions test/Migrator/remove_override.swift

This file was deleted.

126 changes: 0 additions & 126 deletions test/Migrator/remove_override.swift.expected

This file was deleted.