jbcoe created this revision.
jbcoe added a reviewer: krasimir.
jbcoe added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Rename CSharpNullConditionalSq to CSharpNullConditionalLSquare.

Add test for spaces inside [] with C# Null conditionals.

Address comments missed from https://reviews.llvm.org/D75368.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75456

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -607,6 +607,7 @@
 
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
+  verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -972,7 +972,7 @@
       }
       break;
     case tok::question:
-      if (Tok->is(TT_CSharpNullConditionalSq)) {
+      if (Tok->is(TT_CSharpNullConditionalLSquare)) {
         if (!parseSquare())
           return false;
         break;
@@ -1456,7 +1456,7 @@
         return;
       }
       if (CurrentToken->TokenText == "?[") {
-        Current.Type = TT_CSharpNullConditionalSq;
+        Current.Type = TT_CSharpNullConditionalLSquare;
         return;
       }
     }
@@ -2947,11 +2947,11 @@
       return true;
 
     // No space before '?['.
-    if (Right.is(TT_CSharpNullConditionalSq))
+    if (Right.is(TT_CSharpNullConditionalLSquare))
       return false;
 
     // Possible space inside `?[ 0 ]`.
-    if (Left.is(TT_CSharpNullConditionalSq))
+    if (Left.is(TT_CSharpNullConditionalLSquare))
       return Style.SpacesInSquareBrackets;
 
     // space between keywords and paren e.g. "using ("
Index: clang/lib/Format/FormatTokenLexer.cpp
===================================================================
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -345,7 +345,7 @@
 
   if (PeriodOrLSquare->is(tok::l_square)) {
     Question->Tok.setKind(tok::question); // no '?[' in clang tokens.
-    Question->Type = TT_CSharpNullConditionalSq;
+    Question->Type = TT_CSharpNullConditionalLSquare;
   } else {
     Question->Tok.setKind(tok::question); // no '?.' in clang tokens.
     Question->Type = TT_CSharpNullConditional;
Index: clang/lib/Format/FormatToken.h
===================================================================
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -106,7 +106,7 @@
   TYPE(CSharpNullable)                                                         
\
   TYPE(CSharpNullCoalescing)                                                   
\
   TYPE(CSharpNullConditional)                                                  
\
-  TYPE(CSharpNullConditionalSq)                                                
\
+  TYPE(CSharpNullConditionalLSquare)                                           
     \
   TYPE(Unknown)
 
 enum TokenType {


Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -607,6 +607,7 @@
 
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
+  verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -972,7 +972,7 @@
       }
       break;
     case tok::question:
-      if (Tok->is(TT_CSharpNullConditionalSq)) {
+      if (Tok->is(TT_CSharpNullConditionalLSquare)) {
         if (!parseSquare())
           return false;
         break;
@@ -1456,7 +1456,7 @@
         return;
       }
       if (CurrentToken->TokenText == "?[") {
-        Current.Type = TT_CSharpNullConditionalSq;
+        Current.Type = TT_CSharpNullConditionalLSquare;
         return;
       }
     }
@@ -2947,11 +2947,11 @@
       return true;
 
     // No space before '?['.
-    if (Right.is(TT_CSharpNullConditionalSq))
+    if (Right.is(TT_CSharpNullConditionalLSquare))
       return false;
 
     // Possible space inside `?[ 0 ]`.
-    if (Left.is(TT_CSharpNullConditionalSq))
+    if (Left.is(TT_CSharpNullConditionalLSquare))
       return Style.SpacesInSquareBrackets;
 
     // space between keywords and paren e.g. "using ("
Index: clang/lib/Format/FormatTokenLexer.cpp
===================================================================
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -345,7 +345,7 @@
 
   if (PeriodOrLSquare->is(tok::l_square)) {
     Question->Tok.setKind(tok::question); // no '?[' in clang tokens.
-    Question->Type = TT_CSharpNullConditionalSq;
+    Question->Type = TT_CSharpNullConditionalLSquare;
   } else {
     Question->Tok.setKind(tok::question); // no '?.' in clang tokens.
     Question->Type = TT_CSharpNullConditional;
Index: clang/lib/Format/FormatToken.h
===================================================================
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -106,7 +106,7 @@
   TYPE(CSharpNullable)                                                         \
   TYPE(CSharpNullCoalescing)                                                   \
   TYPE(CSharpNullConditional)                                                  \
-  TYPE(CSharpNullConditionalSq)                                                \
+  TYPE(CSharpNullConditionalLSquare)                                                \
   TYPE(Unknown)
 
 enum TokenType {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to