migrator: make sure we can handle the composite change of rename and string representable update. radr://40076924

This commit is contained in:
Xi Ge
2018-05-09 14:48:53 -07:00
parent 1556d62bce
commit 740e336e02
5 changed files with 43 additions and 11 deletions

View File

@@ -346,9 +346,6 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
Editor.replace(Range, RepText);
return true;
}
if (updateStringRepresentableDeclRef(Item, Range)) {
return true;
}
}
return true;
}
@@ -682,20 +679,30 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
auto *RD = getReferencedDecl(Reference);
if (!RD)
return false;
std::string Func;
std::string Rename;
for (auto *Item: getRelatedDiffItems(RD)) {
if (auto *CI = dyn_cast<CommonDiffItem>(Item)) {
if (isSimpleReplacement(Item, Rename)) {
} else if (auto *CI = dyn_cast<CommonDiffItem>(Item)) {
if (CI->isStringRepresentableChange() &&
CI->NodeKind == SDKNodeKind::DeclVar) {
SmallString<256> Buffer;
auto Func = insertHelperFunction(CI->DiffKind, CI->RightComment,
Buffer, FromString);
Editor.insert(WrapperTarget->getStartLoc(), (Twine(Func) + "(").str());
Editor.insertAfterToken(WrapperTarget->getEndLoc(), ")");
return true;
Func = insertHelperFunction(CI->DiffKind, CI->RightComment, Buffer,
FromString);
}
}
}
return false;
if (Func.empty())
return false;
Editor.insert(WrapperTarget->getStartLoc(), (Twine(Func) + "(").str());
Editor.insertAfterToken(WrapperTarget->getEndLoc(), ")");
if (!Rename.empty()) {
auto Range = CharSourceRange(SM, Reference->getStartLoc(),
Lexer::getLocForEndOfToken(SM, Reference->getEndLoc()));
Editor.replace(Range, Rename);
}
return true;
}
bool handleAssignDestMigration(Expr *E) {
@@ -826,7 +833,9 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
bool walkToExprPre(Expr *E) override {
if (handleQualifiedReplacement(E))
return false;
if (handleAssignDestMigration(E) || handleAttributeReference(E))
if (handleAssignDestMigration(E))
return false;
if (handleAttributeReference(E))
return false;
if (auto *CE = dyn_cast<CallExpr>(E)) {
auto Fn = CE->getFn();