diff options
author | Eric Liu <ioeric@google.com> | 2016-07-11 13:53:12 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2016-07-11 13:53:12 +0000 |
commit | a45abc6b0f06d0cf90d0c595bc6ea37596cd5802 (patch) | |
tree | 0d6b81fd2ea5a11ce527046160d9f0d29cab6a92 /tools/clang-format/ClangFormat.cpp | |
parent | 481ab3b5eba4f2ef26b3d3f9cab4b48ea00632ca (diff) |
Make tooling::applyAllReplacements return llvm::Expected<string> instead of empty string to indicate potential error.
Summary:
return llvm::Expected<> to carry error status and error information.
This is the first step towards introducing "Error" into tooling::Replacements.
Reviewers: djasper, klimek
Subscribers: ioeric, klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D21601
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275062 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-format/ClangFormat.cpp')
-rw-r--r-- | tools/clang-format/ClangFormat.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp index a9b077e0b1..27577a5a33 100644 --- a/tools/clang-format/ClangFormat.cpp +++ b/tools/clang-format/ClangFormat.cpp @@ -257,13 +257,16 @@ static bool format(StringRef FileName) { unsigned CursorPosition = Cursor; Replacements Replaces = sortIncludes(FormatStyle, Code->getBuffer(), Ranges, AssumedFileName, &CursorPosition); - std::string ChangedCode = - tooling::applyAllReplacements(Code->getBuffer(), Replaces); + auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replaces); + if (!ChangedCode) { + llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n"; + return true; + } for (const auto &R : Replaces) Ranges.push_back({R.getOffset(), R.getLength()}); bool IncompleteFormat = false; - Replacements FormatChanges = reformat(FormatStyle, ChangedCode, Ranges, + Replacements FormatChanges = reformat(FormatStyle, *ChangedCode, Ranges, AssumedFileName, &IncompleteFormat); Replaces = tooling::mergeReplacements(Replaces, FormatChanges); if (OutputXML) { |