[PATCH] D21602: Changes related to tooling::applyAllReplacements interface change in D21601.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 22 02:06:36 PDT 2016
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21602.61519.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160622/4fa2bc12/attachment.bin>
More information about the cfe-commits
mailing list