Merge branch 'master' into 7.0.x

This commit is contained in:
Clément Fournier
2021-01-18 17:03:59 +01:00
15 changed files with 850 additions and 333 deletions

View File

@ -64,7 +64,7 @@ public class CsTokenizer extends AntlrTokenizer {
private final boolean ignoreLiteralSequences;
private boolean discardingUsings = false;
private boolean discardingNL = false;
private boolean discardingLiterals = false;
private AntlrToken discardingLiteralsUntil = null;
private boolean discardCurrent = false;
CsTokenFilter(final AntlrTokenManager tokenManager, boolean ignoreUsings, boolean ignoreLiteralSequences) {
@ -162,19 +162,24 @@ public class CsTokenizer extends AntlrTokenizer {
private void skipLiteralSequences(final AntlrToken currentToken, final Iterable<AntlrToken> remainingTokens) {
if (ignoreLiteralSequences) {
final int type = currentToken.getKind();
if (type == CSharpLexer.OPEN_BRACE && isSequenceOfLiterals(remainingTokens)) {
discardingLiterals = true;
} else if (type == CSharpLexer.CLOSE_BRACE && discardingLiterals) {
discardingLiterals = false;
discardCurrent = true;
if (isDiscardingLiterals()) {
if (currentToken == discardingLiteralsUntil) { // NOPMD - intentional check for reference equality
discardingLiteralsUntil = null;
discardCurrent = true;
}
} else if (type == CSharpLexer.OPEN_BRACE) {
final AntlrToken finalToken = findEndOfSequenceOfLiterals(remainingTokens);
discardingLiteralsUntil = finalToken;
}
}
}
private boolean isSequenceOfLiterals(final Iterable<AntlrToken> remainingTokens) {
private AntlrToken findEndOfSequenceOfLiterals(final Iterable<AntlrToken> remainingTokens) {
boolean seenLiteral = false;
int braceCount = 0;
for (final AntlrToken token : remainingTokens) {
switch (token.getKind()) {
case CSharpLexer.BIN_INTEGER_LITERAL:
case CSharpLexer.CHARACTER_LITERAL:
case CSharpLexer.HEX_INTEGER_LITERAL:
case CSharpLexer.INTEGER_LITERAL:
@ -183,20 +188,33 @@ public class CsTokenizer extends AntlrTokenizer {
break; // can be skipped; continue to the next token
case CSharpLexer.COMMA:
break; // can be skipped; continue to the next token
case CSharpLexer.OPEN_BRACE:
braceCount++;
break; // curly braces are allowed, as long as they're balanced
case CSharpLexer.CLOSE_BRACE:
// end of the list; skip all contents
return seenLiteral;
braceCount--;
if (braceCount < 0) {
// end of the list; skip all contents
return seenLiteral ? token : null;
} else {
// curly braces are not yet balanced; continue to the next token
break;
}
default:
// some other token than the expected ones; this is not a sequence of literals
return false;
return null;
}
}
return false;
return null;
}
public boolean isDiscardingLiterals() {
return discardingLiteralsUntil != null;
}
@Override
protected boolean isLanguageSpecificDiscarding() {
return discardingUsings || discardingNL || discardingLiterals || discardCurrent;
return discardingUsings || discardingNL || isDiscardingLiterals() || discardCurrent;
}
}
}

View File

@ -3,6 +3,22 @@ using System.Collections;
using System.Collections.Generic;
public class LongLists {
List<byte> l = new List<byte> {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
byte[,] a = {1,2,3,4,5};
byte[,] b = {{1,2},{3,4},{5,6}};
int[,] c = {
157, // decimal literal
0377, // octal literal
36_000_000, // literal with digit separators
0x3fff, // hexadecimal literal
0X3FFF, // same hexadecimal literal
328u, // unsigned value
0x7FFFFFL, // long value
0776745ul, // unsigned long value
18.46, // float
18.46e0, // double with exponent
18.46e1, // double with exponent
0b000001, // binary literal
};
}

View File

@ -37,5 +37,30 @@ L5
L7
[;] 6 7
L8
[byte] 5 9
[\[] 9 10
[,] 10 11
[\]] 11 12
[a] 13 14
[=] 15 16
[;] 28 29
L9
[byte] 5 9
[\[] 9 10
[,] 10 11
[\]] 11 12
[b] 13 14
[=] 15 16
[;] 36 37
L10
[int] 5 8
[\[] 8 9
[,] 9 10
[\]] 10 11
[c] 12 13
[=] 14 15
L23
[;] 6 7
L24
[}] 1 2
EOF