diff options
author | Antonio Maiorano <amaiorano@gmail.com> | 2017-01-17 00:12:27 +0000 |
---|---|---|
committer | Antonio Maiorano <amaiorano@gmail.com> | 2017-01-17 00:12:27 +0000 |
commit | 9163a050930210e6d63abaed418fd89e3c53b827 (patch) | |
tree | 99f9d471798403d09f512c4dbfdabdf1704b4294 /lib/Tooling | |
parent | 115251d60ba426e6891d88f5c68e15f96e2e644e (diff) |
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292174 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling')
-rw-r--r-- | lib/Tooling/Refactoring.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp index 308c1ac48b..954a473f07 100644 --- a/lib/Tooling/Refactoring.cpp +++ b/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; |