ioeric created this revision. ioeric added reviewers: klimek, djasper. ioeric added a subscriber: cfe-commits.
this patch contains changes related to the interface change from http://reviews.llvm.org/D21601. Only submit this patch after D21601 is submitted. http://reviews.llvm.org/D21602 Files: include-fixer/tool/ClangIncludeFixer.cpp unittests/clang-tidy/ClangTidyTest.h Index: unittests/clang-tidy/ClangTidyTest.h =================================================================== --- unittests/clang-tidy/ClangTidyTest.h +++ unittests/clang-tidy/ClangTidyTest.h @@ -17,6 +17,7 @@ #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Tooling.h" +#include "llvm/ADT/Optional.h" #include <map> #include <memory> @@ -121,7 +122,12 @@ Fixes.insert(Error.Fix.begin(), Error.Fix.end()); if (Errors) *Errors = Context.getErrors(); - return tooling::applyAllReplacements(Code, Fixes); + auto Result = tooling::applyAllReplacements(Code, Fixes); + if (!Result) { + // FIXME: propogate the error. + return ""; + } + return *Result; } #define EXPECT_NO_CHANGES(Check, Code) \ Index: include-fixer/tool/ClangIncludeFixer.cpp =================================================================== --- include-fixer/tool/ClangIncludeFixer.cpp +++ include-fixer/tool/ClangIncludeFixer.cpp @@ -211,9 +211,13 @@ tooling::Replacements Replacements = clang::include_fixer::createInsertHeaderReplacements( Code->getBuffer(), FilePath, Context.Headers[0], InsertStyle); - std::string ChangedCode = + auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replacements); - llvm::outs() << ChangedCode; + if (!ChangedCode) { + llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n"; + return 1; + } + llvm::outs() << *ChangedCode; return 0; } @@ -265,9 +269,13 @@ Diagnostics.setClient(&DiagnosticPrinter, false); if (STDINMode) { - std::string ChangedCode = + auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replacements); - llvm::outs() << ChangedCode; + if (!ChangedCode) { + llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n"; + return 1; + } + llvm::outs() << *ChangedCode; return 0; }
Index: unittests/clang-tidy/ClangTidyTest.h =================================================================== --- unittests/clang-tidy/ClangTidyTest.h +++ unittests/clang-tidy/ClangTidyTest.h @@ -17,6 +17,7 @@ #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Tooling.h" +#include "llvm/ADT/Optional.h" #include <map> #include <memory> @@ -121,7 +122,12 @@ Fixes.insert(Error.Fix.begin(), Error.Fix.end()); if (Errors) *Errors = Context.getErrors(); - return tooling::applyAllReplacements(Code, Fixes); + auto Result = tooling::applyAllReplacements(Code, Fixes); + if (!Result) { + // FIXME: propogate the error. + return ""; + } + return *Result; } #define EXPECT_NO_CHANGES(Check, Code) \ Index: include-fixer/tool/ClangIncludeFixer.cpp =================================================================== --- include-fixer/tool/ClangIncludeFixer.cpp +++ include-fixer/tool/ClangIncludeFixer.cpp @@ -211,9 +211,13 @@ tooling::Replacements Replacements = clang::include_fixer::createInsertHeaderReplacements( Code->getBuffer(), FilePath, Context.Headers[0], InsertStyle); - std::string ChangedCode = + auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replacements); - llvm::outs() << ChangedCode; + if (!ChangedCode) { + llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n"; + return 1; + } + llvm::outs() << *ChangedCode; return 0; } @@ -265,9 +269,13 @@ Diagnostics.setClient(&DiagnosticPrinter, false); if (STDINMode) { - std::string ChangedCode = + auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replacements); - llvm::outs() << ChangedCode; + if (!ChangedCode) { + llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n"; + return 1; + } + llvm::outs() << *ChangedCode; return 0; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits