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 | 4f8d99433da80161f85988052f96bc7dc621c4eb (patch) | |
tree | e926d386edbf05c0d8346483a53ac49678e2f284 /clang/tools/clang-format/ClangFormat.cpp | |
parent | 4d8500396454334975ab8bb6766d6521c5140b13 (diff) | |
download | bcm5719-llvm-4f8d99433da80161f85988052f96bc7dc621c4eb.tar.gz bcm5719-llvm-4f8d99433da80161f85988052f96bc7dc621c4eb.zip |
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
llvm-svn: 275062
Diffstat (limited to 'clang/tools/clang-format/ClangFormat.cpp')
-rw-r--r-- | clang/tools/clang-format/ClangFormat.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index a9b077e0b1a..27577a5a336 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/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) { |