Index: include/clang/Rewrite/Core/Rewriter.h =================================================================== --- include/clang/Rewrite/Core/Rewriter.h +++ include/clang/Rewrite/Core/Rewriter.h @@ -245,11 +245,6 @@ /// operation. bool ReplaceText(SourceRange range, SourceRange replacementRange); - /// ReplaceStmt - This replaces a Stmt/Expr with another, using the pretty - /// printer to generate the replacement code. This returns true if the input - /// could not be rewritten, or false if successful. - bool ReplaceStmt(Stmt *From, Stmt *To); - /// \brief Increase indentation for the lines between the given source range. /// To determine what the indentation should be, 'parentIndent' is used /// that should be at a source location with an indentation one degree Index: lib/Frontend/Rewrite/RewriteModernObjC.cpp =================================================================== --- lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -249,27 +249,16 @@ void HandleTranslationUnit(ASTContext &C) override; void ReplaceStmt(Stmt *Old, Stmt *New) { - Stmt *ReplacingStmt = ReplacedNodes[Old]; - - if (ReplacingStmt) - return; // We can't rewrite the same node twice. - - if (DisableReplaceStmt) - return; - - // If replacement succeeded or warning disabled return with no warning. - if (!Rewrite.ReplaceStmt(Old, New)) { - ReplacedNodes[Old] = New; - return; - } - if (SilenceRewriteMacroWarning) - return; - Diags.Report(Context->getFullLoc(Old->getLocStart()), RewriteFailedDiag) - << Old->getSourceRange(); + ReplaceStmtWithRange(Old, New, Old->getSourceRange()); } void ReplaceStmtWithRange(Stmt *Old, Stmt *New, SourceRange SrcRange) { assert(Old != nullptr && New != nullptr && "Expected non-null Stmt's"); + + Stmt *ReplacingStmt = ReplacedNodes[Old]; + if (ReplacingStmt) + return; // We can't rewrite the same node twice. + if (DisableReplaceStmt) return; Index: lib/Frontend/Rewrite/RewriteObjC.cpp =================================================================== --- lib/Frontend/Rewrite/RewriteObjC.cpp +++ lib/Frontend/Rewrite/RewriteObjC.cpp @@ -198,27 +198,16 @@ void HandleTranslationUnit(ASTContext &C) override; void ReplaceStmt(Stmt *Old, Stmt *New) { - Stmt *ReplacingStmt = ReplacedNodes[Old]; - - if (ReplacingStmt) - return; // We can't rewrite the same node twice. - - if (DisableReplaceStmt) - return; - - // If replacement succeeded or warning disabled return with no warning. - if (!Rewrite.ReplaceStmt(Old, New)) { - ReplacedNodes[Old] = New; - return; - } - if (SilenceRewriteMacroWarning) - return; - Diags.Report(Context->getFullLoc(Old->getLocStart()), RewriteFailedDiag) - << Old->getSourceRange(); + ReplaceStmtWithRange(Old, New, Old->getSourceRange()); } void ReplaceStmtWithRange(Stmt *Old, Stmt *New, SourceRange SrcRange) { assert(Old != nullptr && New != nullptr && "Expected non-null Stmt's"); + + Stmt *ReplacingStmt = ReplacedNodes[Old]; + if (ReplacingStmt) + return; // We can't rewrite the same node twice. + if (DisableReplaceStmt) return; Index: lib/Rewrite/CMakeLists.txt =================================================================== --- lib/Rewrite/CMakeLists.txt +++ lib/Rewrite/CMakeLists.txt @@ -10,7 +10,6 @@ TokenRewriter.cpp LINK_LIBS - clangAST clangBasic clangLex ) Index: lib/Rewrite/Rewriter.cpp =================================================================== --- lib/Rewrite/Rewriter.cpp +++ lib/Rewrite/Rewriter.cpp @@ -328,27 +328,6 @@ return ReplaceText(start, origLength, MB.substr(newOffs, newLength)); } -/// ReplaceStmt - This replaces a Stmt/Expr with another, using the pretty -/// printer to generate the replacement code. This returns true if the input -/// could not be rewritten, or false if successful. -bool Rewriter::ReplaceStmt(Stmt *From, Stmt *To) { - assert(From != nullptr && To != nullptr && "Expected non-null Stmt's"); - - // Measaure the old text. - int Size = getRangeSize(From->getSourceRange()); - if (Size == -1) - return true; - - // Get the new text. - std::string SStr; - llvm::raw_string_ostream S(SStr); - To->printPretty(S, nullptr, PrintingPolicy(*LangOpts)); - const std::string &Str = S.str(); - - ReplaceText(From->getLocStart(), Size, Str); - return false; -} - std::string Rewriter::ConvertToString(Stmt *From) { assert(From != nullptr && "Expected non-null Stmt"); std::string SStr;