Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: tools/clang/pass_to_move/PassToMove.cpp

Issue 1534793004: Update the Pass→std::move() tool to handle nested calls to Pass(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/clang/pass_to_move/tests/test-expected.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/pass_to_move/PassToMove.cpp
diff --git a/tools/clang/pass_to_move/PassToMove.cpp b/tools/clang/pass_to_move/PassToMove.cpp
index 2fd947c4ed61d50fe55606de277e23a6b0f84254..c5858f453500c0b72031dc58acdd93416ea1797e 100644
--- a/tools/clang/pass_to_move/PassToMove.cpp
+++ b/tools/clang/pass_to_move/PassToMove.cpp
@@ -41,26 +41,30 @@ class RewriterCallback : public MatchFinder::MatchCallback {
void RewriterCallback::run(const MatchFinder::MatchResult& result) {
const clang::CXXMemberCallExpr* call_expr =
result.Nodes.getNodeAs<clang::CXXMemberCallExpr>("expr");
- const bool is_arrow =
- clang::dyn_cast<clang::MemberExpr>(call_expr->getCallee())->isArrow();
+ const clang::MemberExpr* callee =
+ clang::dyn_cast<clang::MemberExpr>(call_expr->getCallee());
+ const bool is_arrow = callee->isArrow();
const clang::Expr* arg = result.Nodes.getNodeAs<clang::Expr>("arg");
- clang::CharSourceRange arg_range = clang::CharSourceRange::getTokenRange(
- result.SourceManager->getSpellingLoc(arg->getLocStart()),
- result.SourceManager->getSpellingLoc(arg->getLocEnd()));
- std::string new_source_text = "std::move(";
- if (is_arrow)
- new_source_text += "*";
- llvm::StringRef arg_text = clang::Lexer::getSourceText(
- arg_range, *result.SourceManager, result.Context->getLangOpts());
- new_source_text.append(arg_text.data(), arg_text.size());
- new_source_text += ")";
-
- // Replace the entire original expression with std::move(arg).
- clang::CharSourceRange expr_range = clang::CharSourceRange::getTokenRange(
- result.SourceManager->getSpellingLoc(call_expr->getLocStart()),
- result.SourceManager->getSpellingLoc(call_expr->getLocEnd()));
- replacements_->emplace(*result.SourceManager, expr_range, new_source_text);
+ const char kMoveRefText[] = "std::move(";
+ const char kMovePtrText[] = "std::move(*";
+
+ replacements_->emplace(*result.SourceManager,
+ result.SourceManager->getSpellingLoc(
+ arg->getLocStart()),
+ 0,
+ is_arrow ? kMovePtrText : kMoveRefText);
+
+ // Delete everything but the closing parentheses from the original call to
+ // Pass(): the closing parantheses is left to match up with the parantheses
+ // just inserted with std::move.
+ replacements_->emplace(*result.SourceManager,
+ clang::CharSourceRange::getCharRange(
+ result.SourceManager->getSpellingLoc(
+ callee->getOperatorLoc()),
+ result.SourceManager->getSpellingLoc(
+ call_expr->getRParenLoc())),
+ "");
}
} // namespace
« no previous file with comments | « no previous file | tools/clang/pass_to_move/tests/test-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698