[PATCH] D133589: [clang-format] JSON formatting add new option for controlling newlines in json arrays

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 9 23:26:13 PDT 2022


owenpan added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:4405-4408
     if (Left.is(TT_ArrayInitializerLSquare) && Left.is(tok::l_square) &&
         !Right.is(tok::r_square)) {
-      return true;
+      if (Right.is(tok::l_brace))
+        return true;
----------------
Merge the check for `comma` below to avoid repeated code. Also, the check for `l_brace` is redundant.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:4411-4420
+      const auto *Tok = &Right;
+      while (Tok) {
+        if (Tok->isOneOf(tok::l_brace, tok::l_square)) {
+          return true;
+        }
+        if (Tok->isOneOf(tok::r_brace, tok::r_square)) {
+          break;
----------------
Use a `for` loop instead.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:4426-4444
+    if (Left.is(tok::comma)) {
+      if (Right.is(tok::l_brace)) {
+        return true;
+      }
+      // scan to the right if an we see an object or an array inside
+      // then break
+      const auto *Tok = &Right;
----------------
This can be deleted now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133589/new/

https://reviews.llvm.org/D133589



More information about the cfe-commits mailing list