[PATCH] D45168: [clang-format/ObjC] Do not insert space after opening brace of ObjC dict literal

Ben Hamilton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 2 09:13:43 PDT 2018


benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak, krasimir.
Herald added subscribers: cfe-commits, klimek.

https://reviews.llvm.org/D44816 attempted to fix a few cases where `clang-format` incorrectly
inserted a space before the closing brace of an Objective-C dictionary
literal.

This revealed there were still a few cases where we inserted a space
after the opening brace of an Objective-C dictionary literal.

This fixes the formatting to be consistent and adds more tests.

Test Plan: New tests added. Confirmed tests failed before

  diff and passed after diff.
  Ran tests with:
  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D45168

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===================================================================
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1020,9 +1020,18 @@
   verifyFormat("int Foo() {\n"
                "  a12345 = @{a12345 : a12345};\n"
                "}");
+  verifyFormat("int Foo() {\n"
+               "  a12345 = @{a12345 : @(a12345)};\n"
+               "}");
   verifyFormat("int Foo() {\n"
                "  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
                "}");
+  verifyFormat("int Foo() {\n"
+               "  a12345 = @{@(a12345) : a12345};\n"
+               "}");
+  verifyFormat("int Foo() {\n"
+               "  a12345 = @{@(a12345) : @YES};\n"
+               "}");
   Style.SpacesInContainerLiterals = false;
   verifyFormat("int Foo() {\n"
                "  b12345 = @{b12345: b12345};\n"
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2480,6 +2480,9 @@
     return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
     return false;
+  if (Left.is(tok::l_brace) && Left.endsSequence(TT_DictLiteral, tok::at))
+    // Objective-C dictionary literal -> no space after opening brace.
+    return false;
   if (Right.is(tok::r_brace) && Right.MatchingParen &&
       Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at))
     // Objective-C dictionary literal -> no space before closing brace.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45168.140634.patch
Type: text/x-patch
Size: 1540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180402/1a2a31dd/attachment.bin>


More information about the cfe-commits mailing list