Skip to content

Commit

Permalink
Support parsing for Unsigned Right Shift operator (#60501)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyTs authored Apr 4, 2022
1 parent e62a31f commit 6ab2107
Show file tree
Hide file tree
Showing 32 changed files with 2,068 additions and 110 deletions.
11 changes: 11 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,12 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, BindingDia
case SyntaxKind.LeftShiftExpression:
case SyntaxKind.RightShiftExpression:
return BindSimpleBinaryOperator((BinaryExpressionSyntax)node, diagnostics);

case SyntaxKind.UnsignedRightShiftExpression:
// PROTOTYPE(UnsignedRightShift): add real binding
diagnostics.Add(ErrorCode.ERR_BindToBogus, node.Location, ">>>");
return BadExpression(node);

case SyntaxKind.LogicalAndExpression:
case SyntaxKind.LogicalOrExpression:
return BindConditionalLogicalOperator((BinaryExpressionSyntax)node, diagnostics);
Expand Down Expand Up @@ -709,6 +715,11 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, BindingDia
case SyntaxKind.SubtractAssignmentExpression:
return BindCompoundAssignment((AssignmentExpressionSyntax)node, diagnostics);

case SyntaxKind.UnsignedRightShiftAssignmentExpression:
// PROTOTYPE(UnsignedRightShift): add real binding
diagnostics.Add(ErrorCode.ERR_BindToBogus, node.Location, ">>>=");
return BadExpression(node);

case SyntaxKind.CoalesceAssignmentExpression:
return BindNullCoalescingAssignmentOperator((AssignmentExpressionSyntax)node, diagnostics);

Expand Down
4 changes: 4 additions & 0 deletions src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ protected static bool IsSimpleBinaryOperator(SyntaxKind kind)
case SyntaxKind.ExclusiveOrExpression:
case SyntaxKind.LeftShiftExpression:
case SyntaxKind.RightShiftExpression:
// PROTOTYPE(UnsignedRightShift): case SyntaxKind.UnsignedRightShiftExpression
return true;
}
return false;
Expand Down Expand Up @@ -2158,7 +2159,9 @@ private static BinaryOperatorKind SyntaxKindToBinaryOperatorKind(SyntaxKind kind
case SyntaxKind.SubtractAssignmentExpression:
case SyntaxKind.SubtractExpression: return BinaryOperatorKind.Subtraction;
case SyntaxKind.RightShiftAssignmentExpression:
// PROTOTYPE(UnsignedRightShift): case SyntaxKind.UnsignedRightShiftAssignmentExpression:
case SyntaxKind.RightShiftExpression: return BinaryOperatorKind.RightShift;
// PROTOTYPE(UnsignedRightShift): case SyntaxKind.UnsignedRightShiftExpression
case SyntaxKind.LeftShiftAssignmentExpression:
case SyntaxKind.LeftShiftExpression: return BinaryOperatorKind.LeftShift;
case SyntaxKind.EqualsExpression: return BinaryOperatorKind.Equal;
Expand Down Expand Up @@ -2919,6 +2922,7 @@ private static BindValueKind GetBinaryAssignmentKind(SyntaxKind kind)
case SyntaxKind.MultiplyAssignmentExpression:
case SyntaxKind.OrAssignmentExpression:
case SyntaxKind.RightShiftAssignmentExpression:
// PROTOTYPE(UnsignedRightShift): case SyntaxKind.UnsignedRightShiftAssignmentExpression:
case SyntaxKind.SubtractAssignmentExpression:
case SyntaxKind.CoalesceAssignmentExpression:
return BindValueKind.CompoundAssignment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ internal static bool CanBeValidAttributeArgument(ExpressionSyntax node, Binder t
case SyntaxKind.ModuloExpression:
case SyntaxKind.LeftShiftExpression:
case SyntaxKind.RightShiftExpression:
// PROTOTYPE(UnsignedRightShift): case SyntaxKind.UnsignedRightShiftExpression
case SyntaxKind.BitwiseAndExpression:
case SyntaxKind.BitwiseOrExpression:
case SyntaxKind.ExclusiveOrExpression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ internal static string BinaryOperatorNameFromSyntaxKindIfAny(SyntaxKind kind, bo
case SyntaxKind.GreaterThanToken: return WellKnownMemberNames.GreaterThanOperatorName;
case SyntaxKind.GreaterThanEqualsToken: return WellKnownMemberNames.GreaterThanOrEqualOperatorName;
case SyntaxKind.GreaterThanGreaterThanToken: return WellKnownMemberNames.RightShiftOperatorName;
// PROTOTYPE(UnsignedRightShift): case SyntaxKind.GreaterThanGreaterThanGreaterThanToken: return WellKnownMemberNames.UnsignedRightShiftOperatorName;
case SyntaxKind.ExclamationEqualsToken: return WellKnownMemberNames.InequalityOperatorName;
default:
return null;
Expand Down
8 changes: 4 additions & 4 deletions src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36201,6 +36201,7 @@ public BinaryExpressionSyntax BinaryExpression(SyntaxKind kind, ExpressionSyntax
case SyntaxKind.ModuloExpression:
case SyntaxKind.LeftShiftExpression:
case SyntaxKind.RightShiftExpression:
case SyntaxKind.UnsignedRightShiftExpression:
case SyntaxKind.LogicalOrExpression:
case SyntaxKind.LogicalAndExpression:
case SyntaxKind.BitwiseOrExpression:
Expand Down Expand Up @@ -36229,6 +36230,7 @@ public BinaryExpressionSyntax BinaryExpression(SyntaxKind kind, ExpressionSyntax
case SyntaxKind.PercentToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.BarBarToken:
case SyntaxKind.AmpersandAmpersandToken:
case SyntaxKind.BarToken:
Expand Down Expand Up @@ -36276,6 +36278,7 @@ public AssignmentExpressionSyntax AssignmentExpression(SyntaxKind kind, Expressi
case SyntaxKind.OrAssignmentExpression:
case SyntaxKind.LeftShiftAssignmentExpression:
case SyntaxKind.RightShiftAssignmentExpression:
case SyntaxKind.UnsignedRightShiftAssignmentExpression:
case SyntaxKind.CoalesceAssignmentExpression: break;
default: throw new ArgumentException(nameof(kind));
}
Expand All @@ -36295,6 +36298,7 @@ public AssignmentExpressionSyntax AssignmentExpression(SyntaxKind kind, Expressi
case SyntaxKind.BarEqualsToken:
case SyntaxKind.LessThanLessThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
case SyntaxKind.QuestionQuestionEqualsToken: break;
default: throw new ArgumentException(nameof(operatorToken));
}
Expand Down Expand Up @@ -39268,6 +39272,7 @@ public OperatorDeclarationSyntax OperatorDeclaration(Microsoft.CodeAnalysis.Synt
case SyntaxKind.PercentToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.BarToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.CaretToken:
Expand Down Expand Up @@ -39781,6 +39786,7 @@ public OperatorMemberCrefSyntax OperatorMemberCref(SyntaxToken operatorKeyword,
case SyntaxKind.PercentToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.BarToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.CaretToken:
Expand Down Expand Up @@ -41254,6 +41260,7 @@ public static BinaryExpressionSyntax BinaryExpression(SyntaxKind kind, Expressio
case SyntaxKind.ModuloExpression:
case SyntaxKind.LeftShiftExpression:
case SyntaxKind.RightShiftExpression:
case SyntaxKind.UnsignedRightShiftExpression:
case SyntaxKind.LogicalOrExpression:
case SyntaxKind.LogicalAndExpression:
case SyntaxKind.BitwiseOrExpression:
Expand Down Expand Up @@ -41282,6 +41289,7 @@ public static BinaryExpressionSyntax BinaryExpression(SyntaxKind kind, Expressio
case SyntaxKind.PercentToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.BarBarToken:
case SyntaxKind.AmpersandAmpersandToken:
case SyntaxKind.BarToken:
Expand Down Expand Up @@ -41329,6 +41337,7 @@ public static AssignmentExpressionSyntax AssignmentExpression(SyntaxKind kind, E
case SyntaxKind.OrAssignmentExpression:
case SyntaxKind.LeftShiftAssignmentExpression:
case SyntaxKind.RightShiftAssignmentExpression:
case SyntaxKind.UnsignedRightShiftAssignmentExpression:
case SyntaxKind.CoalesceAssignmentExpression: break;
default: throw new ArgumentException(nameof(kind));
}
Expand All @@ -41348,6 +41357,7 @@ public static AssignmentExpressionSyntax AssignmentExpression(SyntaxKind kind, E
case SyntaxKind.BarEqualsToken:
case SyntaxKind.LessThanLessThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
case SyntaxKind.QuestionQuestionEqualsToken: break;
default: throw new ArgumentException(nameof(operatorToken));
}
Expand Down Expand Up @@ -44321,6 +44331,7 @@ public static OperatorDeclarationSyntax OperatorDeclaration(Microsoft.CodeAnalys
case SyntaxKind.PercentToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.BarToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.CaretToken:
Expand Down Expand Up @@ -44834,6 +44845,7 @@ public static OperatorMemberCrefSyntax OperatorMemberCref(SyntaxToken operatorKe
case SyntaxKind.PercentToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.BarToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.CaretToken:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,7 @@ public static BinaryExpressionSyntax BinaryExpression(SyntaxKind kind, Expressio
case SyntaxKind.ModuloExpression:
case SyntaxKind.LeftShiftExpression:
case SyntaxKind.RightShiftExpression:
case SyntaxKind.UnsignedRightShiftExpression:
case SyntaxKind.LogicalOrExpression:
case SyntaxKind.LogicalAndExpression:
case SyntaxKind.BitwiseOrExpression:
Expand All @@ -2678,6 +2679,7 @@ public static BinaryExpressionSyntax BinaryExpression(SyntaxKind kind, Expressio
case SyntaxKind.PercentToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.BarBarToken:
case SyntaxKind.AmpersandAmpersandToken:
case SyntaxKind.BarToken:
Expand Down Expand Up @@ -2712,6 +2714,7 @@ private static SyntaxKind GetBinaryExpressionOperatorTokenKind(SyntaxKind kind)
SyntaxKind.ModuloExpression => SyntaxKind.PercentToken,
SyntaxKind.LeftShiftExpression => SyntaxKind.LessThanLessThanToken,
SyntaxKind.RightShiftExpression => SyntaxKind.GreaterThanGreaterThanToken,
SyntaxKind.UnsignedRightShiftExpression => SyntaxKind.GreaterThanGreaterThanGreaterThanToken,
SyntaxKind.LogicalOrExpression => SyntaxKind.BarBarToken,
SyntaxKind.LogicalAndExpression => SyntaxKind.AmpersandAmpersandToken,
SyntaxKind.BitwiseOrExpression => SyntaxKind.BarToken,
Expand Down Expand Up @@ -2745,6 +2748,7 @@ public static AssignmentExpressionSyntax AssignmentExpression(SyntaxKind kind, E
case SyntaxKind.OrAssignmentExpression:
case SyntaxKind.LeftShiftAssignmentExpression:
case SyntaxKind.RightShiftAssignmentExpression:
case SyntaxKind.UnsignedRightShiftAssignmentExpression:
case SyntaxKind.CoalesceAssignmentExpression: break;
default: throw new ArgumentException(nameof(kind));
}
Expand All @@ -2762,6 +2766,7 @@ public static AssignmentExpressionSyntax AssignmentExpression(SyntaxKind kind, E
case SyntaxKind.BarEqualsToken:
case SyntaxKind.LessThanLessThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
case SyntaxKind.QuestionQuestionEqualsToken: break;
default: throw new ArgumentException(nameof(operatorToken));
}
Expand All @@ -2787,6 +2792,7 @@ private static SyntaxKind GetAssignmentExpressionOperatorTokenKind(SyntaxKind ki
SyntaxKind.OrAssignmentExpression => SyntaxKind.BarEqualsToken,
SyntaxKind.LeftShiftAssignmentExpression => SyntaxKind.LessThanLessThanEqualsToken,
SyntaxKind.RightShiftAssignmentExpression => SyntaxKind.GreaterThanGreaterThanEqualsToken,
SyntaxKind.UnsignedRightShiftAssignmentExpression => SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken,
SyntaxKind.CoalesceAssignmentExpression => SyntaxKind.QuestionQuestionEqualsToken,
_ => throw new ArgumentOutOfRangeException(),
};
Expand Down Expand Up @@ -5233,6 +5239,7 @@ public static OperatorDeclarationSyntax OperatorDeclaration(SyntaxList<Attribute
case SyntaxKind.PercentToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.BarToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.CaretToken:
Expand Down Expand Up @@ -5702,6 +5709,7 @@ public static OperatorMemberCrefSyntax OperatorMemberCref(SyntaxToken operatorKe
case SyntaxKind.PercentToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.BarToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.CaretToken:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,7 @@ public ImplicitElementAccessSyntax Update(BracketedArgumentListSyntax argumentLi
/// <item><description><see cref="SyntaxKind.ModuloExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.LeftShiftExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.RightShiftExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.UnsignedRightShiftExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.LogicalOrExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.LogicalAndExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.BitwiseOrExpression"/></description></item>
Expand Down Expand Up @@ -1720,6 +1721,7 @@ public BinaryExpressionSyntax Update(ExpressionSyntax left, SyntaxToken operator
/// <item><description><see cref="SyntaxKind.OrAssignmentExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.LeftShiftAssignmentExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.RightShiftAssignmentExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.UnsignedRightShiftAssignmentExpression"/></description></item>
/// <item><description><see cref="SyntaxKind.CoalesceAssignmentExpression"/></description></item>
/// </list>
/// </remarks>
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Parser/Blender.Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ internal static bool IsFabricatedToken(SyntaxKind kind)
{
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
case SyntaxKind.ExclamationExclamationToken:
return true;
default:
Expand Down
Loading

0 comments on commit 6ab2107

Please sign in to comment.