From 0d7d9c20a531d843e7081154c96e84890b746131 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Tue, 17 Jan 2017 00:13:32 +0000 Subject: [PATCH] Update tools to use new getStyle API Depends on https://reviews.llvm.org/D28081 Differential Revision: https://reviews.llvm.org/D28315 llvm-svn: 292175 --- clang-tools-extra/change-namespace/ChangeNamespace.cpp | 9 ++++++--- .../tool/ClangApplyReplacementsMain.cpp | 11 +++++++++-- clang-tools-extra/clang-move/ClangMove.cpp | 9 ++++++--- clang-tools-extra/clang-tidy/ClangTidy.cpp | 8 ++++++-- .../include-fixer/tool/ClangIncludeFixer.cpp | 17 ++++++++++++----- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/clang-tools-extra/change-namespace/ChangeNamespace.cpp b/clang-tools-extra/change-namespace/ChangeNamespace.cpp index b2f31a9..35ea707 100644 --- a/clang-tools-extra/change-namespace/ChangeNamespace.cpp +++ b/clang-tools-extra/change-namespace/ChangeNamespace.cpp @@ -883,11 +883,14 @@ void ChangeNamespaceTool::onEndOfTranslationUnit() { // Add replacements referring to the changed code to existing replacements, // which refers to the original code. Replaces = Replaces.merge(NewReplacements); - format::FormatStyle Style = - format::getStyle("file", FilePath, FallbackStyle); + auto Style = format::getStyle("file", FilePath, FallbackStyle); + if (!Style) { + llvm::errs() << llvm::toString(Style.takeError()) << "\n"; + continue; + } // Clean up old namespaces if there is nothing in it after moving. auto CleanReplacements = - format::cleanupAroundReplacements(Code, Replaces, Style); + format::cleanupAroundReplacements(Code, Replaces, *Style); if (!CleanReplacements) { llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n"; continue; diff --git a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp index 0881e67..3ca2680 100644 --- a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp +++ b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp @@ -208,8 +208,15 @@ int main(int argc, char **argv) { // Determine a formatting style from options. format::FormatStyle FormatStyle; - if (DoFormat) - FormatStyle = format::getStyle(FormatStyleOpt, FormatStyleConfig, "LLVM"); + if (DoFormat) { + auto FormatStyleOrError = + format::getStyle(FormatStyleOpt, FormatStyleConfig, "LLVM"); + if (!FormatStyleOrError) { + llvm::errs() << llvm::toString(FormatStyleOrError.takeError()) << "\n"; + return 1; + } + FormatStyle = *FormatStyleOrError; + } TUReplacements TURs; TUReplacementFiles TUFiles; diff --git a/clang-tools-extra/clang-move/ClangMove.cpp b/clang-tools-extra/clang-move/ClangMove.cpp index cfd36d6..be3fca0 100644 --- a/clang-tools-extra/clang-move/ClangMove.cpp +++ b/clang-tools-extra/clang-move/ClangMove.cpp @@ -742,10 +742,13 @@ void ClangMoveTool::removeDeclsInOldFiles() { // Ignore replacements for new.h/cc. if (SI == FilePathToFileID.end()) continue; llvm::StringRef Code = SM.getBufferData(SI->second); - format::FormatStyle Style = - format::getStyle("file", FilePath, Context->FallbackStyle); + auto Style = format::getStyle("file", FilePath, Context->FallbackStyle); + if (!Style) { + llvm::errs() << llvm::toString(Style.takeError()) << "\n"; + continue; + } auto CleanReplacements = format::cleanupAroundReplacements( - Code, Context->FileToReplacements[FilePath], Style); + Code, Context->FileToReplacements[FilePath], *Style); if (!CleanReplacements) { llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n"; diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index e107e8a..75aaefd 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -197,10 +197,14 @@ public: continue; } StringRef Code = Buffer.get()->getBuffer(); - format::FormatStyle Style = format::getStyle("file", File, FormatStyle); + auto Style = format::getStyle("file", File, FormatStyle); + if (!Style) { + llvm::errs() << llvm::toString(Style.takeError()) << "\n"; + continue; + } llvm::Expected CleanReplacements = format::cleanupAroundReplacements(Code, FileAndReplacements.second, - Style); + *Style); if (!CleanReplacements) { llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n"; continue; diff --git a/clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp b/clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp index 47942a9..15a7158 100644 --- a/clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp +++ b/clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp @@ -303,10 +303,13 @@ int includeFixerMain(int argc, const char **argv) { const IncludeFixerContext::HeaderInfo &RHS) { return LHS.QualifiedName == RHS.QualifiedName; }); - format::FormatStyle InsertStyle = - format::getStyle("file", Context.getFilePath(), Style); + auto InsertStyle = format::getStyle("file", Context.getFilePath(), Style); + if (!InsertStyle) { + llvm::errs() << llvm::toString(InsertStyle.takeError()) << "\n"; + return 1; + } auto Replacements = clang::include_fixer::createIncludeFixerReplacements( - Code->getBuffer(), Context, InsertStyle, + Code->getBuffer(), Context, *InsertStyle, /*AddQualifiers=*/IsUniqueQualifiedName); if (!Replacements) { errs() << "Failed to create replacements: " @@ -378,7 +381,11 @@ int includeFixerMain(int argc, const char **argv) { std::vector FixerReplacements; for (const auto &Context : Contexts) { StringRef FilePath = Context.getFilePath(); - format::FormatStyle InsertStyle = format::getStyle("file", FilePath, Style); + auto InsertStyle = format::getStyle("file", FilePath, Style); + if (!InsertStyle) { + llvm::errs() << llvm::toString(InsertStyle.takeError()) << "\n"; + return 1; + } auto Buffer = llvm::MemoryBuffer::getFile(FilePath); if (!Buffer) { errs() << "Couldn't open file: " + FilePath.str() + ": " @@ -387,7 +394,7 @@ int includeFixerMain(int argc, const char **argv) { } auto Replacements = clang::include_fixer::createIncludeFixerReplacements( - Buffer.get()->getBuffer(), Context, InsertStyle); + Buffer.get()->getBuffer(), Context, *InsertStyle); if (!Replacements) { errs() << "Failed to create replacement: " << llvm::toString(Replacements.takeError()) << "\n"; -- 2.7.4