summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-07-11 13:53:12 +0000
committerEric Liu <ioeric@google.com>2016-07-11 13:53:12 +0000
commit4f8d99433da80161f85988052f96bc7dc621c4eb (patch)
treee926d386edbf05c0d8346483a53ac49678e2f284 /clang/lib/Format
parent4d8500396454334975ab8bb6766d6521c5140b13 (diff)
downloadbcm5719-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/lib/Format')
-rw-r--r--clang/lib/Format/Format.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 6f7ee274e99..32d6bb855ad 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1393,27 +1393,29 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code,
}
template <typename T>
-static tooling::Replacements
+static llvm::Expected<tooling::Replacements>
processReplacements(T ProcessFunc, StringRef Code,
const tooling::Replacements &Replaces,
const FormatStyle &Style) {
if (Replaces.empty())
return tooling::Replacements();
- std::string NewCode = applyAllReplacements(Code, Replaces);
+ auto NewCode = applyAllReplacements(Code, Replaces);
+ if (!NewCode)
+ return NewCode.takeError();
std::vector<tooling::Range> ChangedRanges =
tooling::calculateChangedRanges(Replaces);
StringRef FileName = Replaces.begin()->getFilePath();
tooling::Replacements FormatReplaces =
- ProcessFunc(Style, NewCode, ChangedRanges, FileName);
+ ProcessFunc(Style, *NewCode, ChangedRanges, FileName);
return mergeReplacements(Replaces, FormatReplaces);
}
-tooling::Replacements formatReplacements(StringRef Code,
- const tooling::Replacements &Replaces,
- const FormatStyle &Style) {
+llvm::Expected<tooling::Replacements>
+formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
+ const FormatStyle &Style) {
// We need to use lambda function here since there are two versions of
// `sortIncludes`.
auto SortIncludes = [](const FormatStyle &Style, StringRef Code,
@@ -1421,8 +1423,10 @@ tooling::Replacements formatReplacements(StringRef Code,
StringRef FileName) -> tooling::Replacements {
return sortIncludes(Style, Code, Ranges, FileName);
};
- tooling::Replacements SortedReplaces =
+ auto SortedReplaces =
processReplacements(SortIncludes, Code, Replaces, Style);
+ if (!SortedReplaces)
+ return SortedReplaces.takeError();
// We need to use lambda function here since there are two versions of
// `reformat`.
@@ -1431,7 +1435,7 @@ tooling::Replacements formatReplacements(StringRef Code,
StringRef FileName) -> tooling::Replacements {
return reformat(Style, Code, Ranges, FileName);
};
- return processReplacements(Reformat, Code, SortedReplaces, Style);
+ return processReplacements(Reformat, Code, *SortedReplaces, Style);
}
namespace {
@@ -1591,7 +1595,7 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces,
} // anonymous namespace
-tooling::Replacements
+llvm::Expected<tooling::Replacements>
cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces,
const FormatStyle &Style) {
// We need to use lambda function here since there are two versions of
OpenPOWER on IntegriCloud