llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: Jannik Silvanus (jasilvanus)

<details>
<summary>Changes</summary>

When serializing a formatting style to YAML, we were emitting a comment `# 
BasedOnStyle: &lt;style&gt;` if the serialized formatting style matches one of 
the known styles. This is useful, but mis-uses the YAML API.

An upcoming change to fix keys with special characters by quoting them breaks 
this, 
and will emit a non-comment **key** `'# BasedOnStyle': &lt;style&gt;` instead.
(https://github.com/llvm/llvm-project/pull/88763)

Thus, remove this hack.
Instead, we emit an ordinary key OrigBasedOnStyle that is ignored when reading 
back the data. 
An alternative would be to just remove it completely.

Ideally, we'd emit a proper comment, but our YAML API doesn't support that.

---
Full diff: https://github.com/llvm/llvm-project/pull/89228.diff


1 Files Affected:

- (modified) clang/lib/Format/Format.cpp (+7-1) 


``````````diff
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ccb2c9190e2eff..9b311343387ead 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -807,12 +807,18 @@ template <> struct MappingTraits<FormatStyle> {
         FormatStyle PredefinedStyle;
         if (getPredefinedStyle(StyleName, Style.Language, &PredefinedStyle) &&
             Style == PredefinedStyle) {
-          IO.mapOptional("# BasedOnStyle", StyleName);
+          // For convenience, emit the info which style this matches. However,
+          // setting BasedOnStyle will override all other keys when importing,
+          // so we set a helper key that is ignored when importing.
+          // Ideally, we'd want a YAML comment here, but that's not supported.
+          IO.mapOptional("OrigBasedOnStyle", StyleName);
           BasedOnStyle = StyleName;
           break;
         }
       }
     } else {
+      StringRef OrigBasedOnStyle; // ignored
+      IO.mapOptional("OrigBasedOnStyle", OrigBasedOnStyle);
       IO.mapOptional("BasedOnStyle", BasedOnStyle);
       if (!BasedOnStyle.empty()) {
         FormatStyle::LanguageKind OldLanguage = Style.Language;

``````````

</details>


https://github.com/llvm/llvm-project/pull/89228
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to