amaiorano updated this revision to Diff 84539.
amaiorano added a comment.

Rebased changes on latest. No functional changes in this diff since last.

All tests pass (on Windows).


https://reviews.llvm.org/D28315

Files:
  change-namespace/ChangeNamespace.cpp
  clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
  clang-move/ClangMove.cpp
  clang-tidy/ClangTidy.cpp
  include-fixer/tool/ClangIncludeFixer.cpp

Index: include-fixer/tool/ClangIncludeFixer.cpp
===================================================================
--- include-fixer/tool/ClangIncludeFixer.cpp
+++ include-fixer/tool/ClangIncludeFixer.cpp
@@ -303,10 +303,13 @@
            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,16 +381,20 @@
   std::vector<tooling::Replacements> 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() + ": "
              << Buffer.getError().message() + "\n";
       return 1;
     }
 
     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";
Index: clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -197,10 +197,14 @@
           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<Replacements> CleanReplacements =
             format::cleanupAroundReplacements(Code, FileAndReplacements.second,
-                                              Style);
+                                              *Style);
         if (!CleanReplacements) {
           llvm::errs() << llvm::toString(CleanReplacements.takeError()) << "\n";
           continue;
Index: clang-move/ClangMove.cpp
===================================================================
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -742,10 +742,13 @@
     // 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";
Index: clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
===================================================================
--- clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -208,8 +208,15 @@
 
   // 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;
Index: change-namespace/ChangeNamespace.cpp
===================================================================
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -883,11 +883,14 @@
     // 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;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to