[clang] 9c4afce - [clang-format] Rename CSharpNullConditionalSq and add missing test

Jonathan Coe via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 2 07:48:58 PST 2020


Author: Jonathan Coe
Date: 2020-03-02T15:46:33Z
New Revision: 9c4afce7024aa1fe4efe2631240d1d766b4ea257

URL: https://github.com/llvm/llvm-project/commit/9c4afce7024aa1fe4efe2631240d1d766b4ea257
DIFF: https://github.com/llvm/llvm-project/commit/9c4afce7024aa1fe4efe2631240d1d766b4ea257.diff

LOG: [clang-format] Rename CSharpNullConditionalSq and add missing test

Summary:
Rename CSharpNullConditionalSq to CSharpNullConditionalLSquare.

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

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

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75456

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index ac117840ea33..d0d08e470e6c 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -106,7 +106,7 @@ namespace format {
   TYPE(CSharpNullable)                                                         \
   TYPE(CSharpNullCoalescing)                                                   \
   TYPE(CSharpNullConditional)                                                  \
-  TYPE(CSharpNullConditionalSq)                                                \
+  TYPE(CSharpNullConditionalLSquare)                                           \
   TYPE(Unknown)
 
 enum TokenType {

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp
index da73361ee3d5..8fa78b773e5e 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -345,7 +345,7 @@ bool FormatTokenLexer::tryMergeCSharpNullConditional() {
 
   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;

diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index e1e08686ac44..35e0b423cfc4 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -972,7 +972,7 @@ class AnnotatingParser {
       }
       break;
     case tok::question:
-      if (Tok->is(TT_CSharpNullConditionalSq)) {
+      if (Tok->is(TT_CSharpNullConditionalLSquare)) {
         if (!parseSquare())
           return false;
         break;
@@ -1456,7 +1456,7 @@ class AnnotatingParser {
         return;
       }
       if (CurrentToken->TokenText == "?[") {
-        Current.Type = TT_CSharpNullConditionalSq;
+        Current.Type = TT_CSharpNullConditionalLSquare;
         return;
       }
     }
@@ -2947,11 +2947,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
       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 ("

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index 0bc49856375b..d22e0da82321 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -607,6 +607,7 @@ TEST_F(FormatTestCSharp, CSharpSpaces) {
 
   Style.SpacesInSquareBrackets = true;
   verifyFormat(R"(private float[ , ] Values;)", Style);
+  verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {


        


More information about the cfe-commits mailing list