[PATCH] D90133: clang-format: Allow fallback-style to take formatting arguments

Joel Grunbaum via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 25 23:20:57 PDT 2020


Chizi123 created this revision.
Chizi123 added reviewers: llvm-commits, cfe-commits, djasper, rsmith, klimek.
Herald added a project: clang.
Chizi123 requested review of this revision.

Currently, -style is capable of accepting configuration options in its argument, while -fallback-style must be a predefined style.
This allows -fallback-style to take an argument formatted like a style argument.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90133

Files:
  clang/lib/Format/Format.cpp


Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2844,8 +2844,15 @@
   FormatStyle Style = getLLVMStyle(guessLanguage(FileName, Code));
 
   FormatStyle FallbackStyle = getNoStyle();
-  if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle))
+  if (FallbackStyleName.startswith("{")) {
+    if (std::error_code ec = parseConfiguration(
+            FallbackStyleName, &FallbackStyle, AllowUnknownOptions))
+      return make_string_error("Error parsing -fallback-style: " +
+                               ec.message());
+  } else if (!getPredefinedStyle(FallbackStyleName, Style.Language,
+                                 &FallbackStyle)) {
     return make_string_error("Invalid fallback style \"" + FallbackStyleName);
+  }
 
   if (StyleName.startswith("{")) {
     // Parse YAML/JSON style from the command line.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90133.300579.patch
Type: text/x-patch
Size: 961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201026/37bbe2cb/attachment.bin>


More information about the llvm-commits mailing list