forked from OSchip/llvm-project
[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
This commit is contained in:
parent
675326466b
commit
9c4afce702
|
@ -106,7 +106,7 @@ namespace format {
|
||||||
TYPE(CSharpNullable) \
|
TYPE(CSharpNullable) \
|
||||||
TYPE(CSharpNullCoalescing) \
|
TYPE(CSharpNullCoalescing) \
|
||||||
TYPE(CSharpNullConditional) \
|
TYPE(CSharpNullConditional) \
|
||||||
TYPE(CSharpNullConditionalSq) \
|
TYPE(CSharpNullConditionalLSquare) \
|
||||||
TYPE(Unknown)
|
TYPE(Unknown)
|
||||||
|
|
||||||
enum TokenType {
|
enum TokenType {
|
||||||
|
|
|
@ -345,7 +345,7 @@ bool FormatTokenLexer::tryMergeCSharpNullConditional() {
|
||||||
|
|
||||||
if (PeriodOrLSquare->is(tok::l_square)) {
|
if (PeriodOrLSquare->is(tok::l_square)) {
|
||||||
Question->Tok.setKind(tok::question); // no '?[' in clang tokens.
|
Question->Tok.setKind(tok::question); // no '?[' in clang tokens.
|
||||||
Question->Type = TT_CSharpNullConditionalSq;
|
Question->Type = TT_CSharpNullConditionalLSquare;
|
||||||
} else {
|
} else {
|
||||||
Question->Tok.setKind(tok::question); // no '?.' in clang tokens.
|
Question->Tok.setKind(tok::question); // no '?.' in clang tokens.
|
||||||
Question->Type = TT_CSharpNullConditional;
|
Question->Type = TT_CSharpNullConditional;
|
||||||
|
|
|
@ -972,7 +972,7 @@ private:
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case tok::question:
|
case tok::question:
|
||||||
if (Tok->is(TT_CSharpNullConditionalSq)) {
|
if (Tok->is(TT_CSharpNullConditionalLSquare)) {
|
||||||
if (!parseSquare())
|
if (!parseSquare())
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
|
@ -1456,7 +1456,7 @@ private:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (CurrentToken->TokenText == "?[") {
|
if (CurrentToken->TokenText == "?[") {
|
||||||
Current.Type = TT_CSharpNullConditionalSq;
|
Current.Type = TT_CSharpNullConditionalLSquare;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2947,11 +2947,11 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// No space before '?['.
|
// No space before '?['.
|
||||||
if (Right.is(TT_CSharpNullConditionalSq))
|
if (Right.is(TT_CSharpNullConditionalLSquare))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Possible space inside `?[ 0 ]`.
|
// Possible space inside `?[ 0 ]`.
|
||||||
if (Left.is(TT_CSharpNullConditionalSq))
|
if (Left.is(TT_CSharpNullConditionalLSquare))
|
||||||
return Style.SpacesInSquareBrackets;
|
return Style.SpacesInSquareBrackets;
|
||||||
|
|
||||||
// space between keywords and paren e.g. "using ("
|
// space between keywords and paren e.g. "using ("
|
||||||
|
|
|
@ -607,6 +607,7 @@ TEST_F(FormatTestCSharp, CSharpSpaces) {
|
||||||
|
|
||||||
Style.SpacesInSquareBrackets = true;
|
Style.SpacesInSquareBrackets = true;
|
||||||
verifyFormat(R"(private float[ , ] Values;)", Style);
|
verifyFormat(R"(private float[ , ] Values;)", Style);
|
||||||
|
verifyFormat(R"(string dirPath = args?[ 0 ];)", Style);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatTestCSharp, CSharpNullableTypes) {
|
TEST_F(FormatTestCSharp, CSharpNullableTypes) {
|
||||||
|
|
Loading…
Reference in New Issue