aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Tooling/Refactoring.cpp
diff options
context:
space:
mode:
authorAntonio Maiorano <amaiorano@gmail.com>2017-01-17 00:12:27 +0000
committerAntonio Maiorano <amaiorano@gmail.com>2017-01-17 00:12:27 +0000
commit3adfb6a3eed268a04275334147a57e165ceb5669 (patch)
treed9e2df760d8962b208a846fb77da1f30e8edb99e /clang/lib/Tooling/Refactoring.cpp
parent2aab1d45ff6e76c851524b1933666681c6a87fc5 (diff)
downloadllvm-3adfb6a3eed268a04275334147a57e165ceb5669.zip
llvm-3adfb6a3eed268a04275334147a57e165ceb5669.tar.gz
llvm-3adfb6a3eed268a04275334147a57e165ceb5669.tar.bz2
clang-format: Make GetStyle return Expected<FormatStyle> instead of FormatStyle
Change the contract of GetStyle so that it returns an error when an error occurs (i.e. when it writes to stderr), and only returns the fallback style when it can't find a configuration file. Differential Revision: https://reviews.llvm.org/D28081 llvm-svn: 292174
Diffstat (limited to 'clang/lib/Tooling/Refactoring.cpp')
-rw-r--r--clang/lib/Tooling/Refactoring.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/Tooling/Refactoring.cpp b/clang/lib/Tooling/Refactoring.cpp
index 308c1ac..954a473 100644
--- a/clang/lib/Tooling/Refactoring.cpp
+++ b/clang/lib/Tooling/Refactoring.cpp
@@ -68,8 +68,8 @@ int RefactoringTool::saveRewrittenFiles(Rewriter &Rewrite) {
}
bool formatAndApplyAllReplacements(
- const std::map<std::string, Replacements> &FileToReplaces, Rewriter &Rewrite,
- StringRef Style) {
+ const std::map<std::string, Replacements> &FileToReplaces,
+ Rewriter &Rewrite, StringRef Style) {
SourceManager &SM = Rewrite.getSourceMgr();
FileManager &Files = SM.getFileManager();
@@ -83,9 +83,14 @@ bool formatAndApplyAllReplacements(
FileID ID = SM.getOrCreateFileID(Entry, SrcMgr::C_User);
StringRef Code = SM.getBufferData(ID);
- format::FormatStyle CurStyle = format::getStyle(Style, FilePath, "LLVM");
+ auto CurStyle = format::getStyle(Style, FilePath, "LLVM");
+ if (!CurStyle) {
+ llvm::errs() << llvm::toString(CurStyle.takeError()) << "\n";
+ return false;
+ }
+
auto NewReplacements =
- format::formatReplacements(Code, CurReplaces, CurStyle);
+ format::formatReplacements(Code, CurReplaces, *CurStyle);
if (!NewReplacements) {
llvm::errs() << llvm::toString(NewReplacements.takeError()) << "\n";
return false;