| 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
|
|
|