本文整理汇总了C#中BinaryExpressionSyntax.Kind方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpressionSyntax.Kind方法的具体用法?C# BinaryExpressionSyntax.Kind怎么用?C# BinaryExpressionSyntax.Kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryExpressionSyntax
的用法示例。
在下文中一共展示了BinaryExpressionSyntax.Kind方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryFlip
static bool TryFlip(BinaryExpressionSyntax expr, out SyntaxKind flippedKind, out string operatorText)
{
switch (expr.Kind())
{
case SyntaxKind.LessThanExpression:
flippedKind = SyntaxKind.GreaterThanExpression;
operatorText = ">";
return true;
case SyntaxKind.LessThanOrEqualExpression:
flippedKind = SyntaxKind.GreaterThanOrEqualExpression;
operatorText = ">=";
return true;
case SyntaxKind.GreaterThanExpression:
flippedKind = SyntaxKind.LessThanExpression;
operatorText = "<";
return true;
case SyntaxKind.GreaterThanOrEqualExpression:
flippedKind = SyntaxKind.LessThanOrEqualExpression;
operatorText = "<=";
return true;
}
flippedKind = SyntaxKind.None;
operatorText = null;
return false;
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:25,代码来源:FlipRelationalOperatorArgumentsCodeRefactoringProvider.cs
示例2: ChangeOperator
private static BinaryExpressionSyntax ChangeOperator(BinaryExpressionSyntax binary)
{
return
SyntaxFactory.BinaryExpression(
OppositeExpressionKinds[binary.Kind()],
binary.Left,
binary.Right)
.WithTriviaFrom(binary);
}
示例3: VisitBinaryExpression
public override void VisitBinaryExpression(BinaryExpressionSyntax node)
{
node.Left.Accept(this);
node.Right.Accept(this);
switch (node.Kind())
{
case SyntaxKind.LogicalAndExpression:
case SyntaxKind.LogicalOrExpression:
break;
default:
throw new InvalidPreprocessorExpressionException("Expected logical and/or expression");
}
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:14,代码来源:PreprocessorSymbolTracker.cs
示例4: VisitBinaryExpression
public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
{
Tristate leftState = _expressionEvaluator.EvaluateExpression(node.Left);
Tristate rightState = _expressionEvaluator.EvaluateExpression(node.Right);
var left = (ExpressionSyntax)node.Left.Accept(this);
var right = (ExpressionSyntax)node.Right.Accept(this);
if (node.Left != left)
{
node = node.WithLeft(left);
}
if (node.Right != right)
{
node = node.WithRight(right);
}
if (leftState != Tristate.Varying && rightState != Tristate.Varying)
{
return node;
}
ExpressionSyntax newExpression = null;
if (node.Kind() == SyntaxKind.LogicalAndExpression)
{
if (leftState == Tristate.True)
{
// true && varying == varying
newExpression = right;
}
else if (rightState == Tristate.True)
{
// varying && true == varying
newExpression = left;
}
}
else if (node.Kind() == SyntaxKind.LogicalOrExpression)
{
if (leftState == Tristate.False)
{
// false || varying == varying
newExpression = right;
}
else if (rightState == Tristate.False)
{
// varying || false == varying
newExpression = left;
}
}
if (newExpression != null)
{
return newExpression
.WithLeadingTrivia(node.GetLeadingTrivia())
.WithTrailingTrivia(node.GetTrailingTrivia());
}
return node;
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:61,代码来源:PreprocessorExpressionSimplifier.cs
示例5: VisitBinaryExpression
public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
{
_cancellationToken.ThrowIfCancellationRequested();
// Special case: We parenthesize to avoid a situation where inlining an
// expression can cause code to parse differently. The canonical case is...
//
// var x = 0;
// var y = (1 + 2);
// var z = new[] { x < x, x > y };
//
// Inlining 'y' in the code above will produce code that parses differently
// (i.e. as a generic method invocation).
//
// var z = new[] { x < x, x > (1 + 2) };
var result = (BinaryExpressionSyntax)base.VisitBinaryExpression(node);
if ((node.Kind() == SyntaxKind.GreaterThanExpression || node.Kind() == SyntaxKind.RightShiftExpression) && !node.IsParentKind(SyntaxKind.ParenthesizedExpression))
{
return result.Parenthesize();
}
return result;
}
示例6: TryGenerateBinaryOperation
private bool TryGenerateBinaryOperation(BinaryExpressionSyntax binaryExpression)
{
BinaryOperatorKind kind;
switch (binaryExpression.Kind())
{
case SyntaxKind.AddExpression:
kind = BinaryOperatorKind.Plus;
break;
case SyntaxKind.BitwiseOrExpression:
kind = BinaryOperatorKind.BitwiseOr;
break;
case SyntaxKind.BitwiseAndExpression:
kind = BinaryOperatorKind.BitwiseAnd;
break;
default:
return false;
}
using (BinaryOperationTag(kind))
{
return TryGenerateExpression(binaryExpression.Left)
&& TryGenerateExpression(binaryExpression.Right);
}
}
示例7: VisitBinaryExpression
public override bool VisitBinaryExpression(BinaryExpressionSyntax node)
{
switch (node.Kind())
{
case SyntaxKind.LogicalAndExpression:
case SyntaxKind.LogicalOrExpression:
return Visit(node.Left);
}
return base.VisitBinaryExpression(node);
}
示例8: AnalyzeComparisonWithFlags
static bool AnalyzeComparisonWithFlags(BinaryExpressionSyntax boP, out ExpressionSyntax flagsExpression, out ExpressionSyntax targetExpression, out bool testFlagset)
{
var left = boP.Left.SkipParens();
var right = boP.Right.SkipParens();
testFlagset = boP.Kind() != SyntaxKind.EqualsExpression;
flagsExpression = targetExpression = null;
BinaryExpressionSyntax primExp;
if (left.IsKind(SyntaxKind.BitwiseAndExpression))
{
primExp = left as BinaryExpressionSyntax;
flagsExpression = right;
}
else
{
primExp = right as BinaryExpressionSyntax;
flagsExpression = left;
}
if (primExp == null)
return false;
if (primExp.Left.IsEquivalentTo(flagsExpression))
{
DecomposeBinaryOperator(primExp, out flagsExpression, out targetExpression);
return true;
}
if (primExp.Right.IsEquivalentTo(flagsExpression))
{
DecomposeBinaryOperator(primExp, out flagsExpression, out targetExpression);
return true;
}
return false;
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:38,代码来源:ConvertBitwiseFlagComparisonToHasFlagsCodeRefactoringProvider.cs
示例9: AnalyzeComparisonWithNull
static bool AnalyzeComparisonWithNull(BinaryExpressionSyntax boP, out ExpressionSyntax flagsExpression, out ExpressionSyntax targetExpression, out bool testFlagset)
{
var left = boP.Left.SkipParens();
var right = boP.Right.SkipParens();
testFlagset = boP.Kind() == SyntaxKind.EqualsExpression;
flagsExpression = targetExpression = null;
ExpressionSyntax primExp;
BinaryExpressionSyntax binOp;
if (left.IsKind(SyntaxKind.NumericLiteralExpression))
{
primExp = left;
binOp = right as BinaryExpressionSyntax;
}
else
{
primExp = right;
binOp = left as BinaryExpressionSyntax;
}
if (binOp == null)
{
return false;
}
DecomposeBinaryOperator(binOp, out flagsExpression, out targetExpression);
return primExp != null && primExp.ToString() == "0";
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:28,代码来源:ConvertBitwiseFlagComparisonToHasFlagsCodeRefactoringProvider.cs
示例10: VisitBinaryExpression
public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
{
bool isOrAsNode = node.Kind() == SyntaxKind.AsExpression || node.Kind() == SyntaxKind.IsExpression;
var result = (ExpressionSyntax)base.VisitBinaryExpression(node);
if (result != node && isOrAsNode)
{
// In order to handle cases in which simplifying a name would result in code
// that parses different, we pre-emptively add parentheses that will be
// simplified away later.
//
// For example, this code...
//
// var x = y as Nullable<int> + 1;
//
// ...should simplify as...
//
// var x = (y as int?) + 1;
return result.Parenthesize().WithAdditionalAnnotations(Formatter.Annotation);
}
return result;
}
示例11: IsComparisonOfZeroAndSomethingNeverLessThanZero
private bool IsComparisonOfZeroAndSomethingNeverLessThanZero(BinaryExpressionSyntax binaryExpression, SemanticModel semanticModel, CancellationToken cancellationToken)
{
var canSimplify = false;
if (binaryExpression.Kind() == SyntaxKind.GreaterThanExpression &&
binaryExpression.Right.Kind() == SyntaxKind.NumericLiteralExpression)
{
canSimplify = CanSimplifyToLengthEqualsZeroExpression(
binaryExpression.Left,
(LiteralExpressionSyntax)binaryExpression.Right,
semanticModel,
cancellationToken);
}
else if (binaryExpression.Kind() == SyntaxKind.LessThanExpression &&
binaryExpression.Left.Kind() == SyntaxKind.NumericLiteralExpression)
{
canSimplify = CanSimplifyToLengthEqualsZeroExpression(
binaryExpression.Right,
(LiteralExpressionSyntax)binaryExpression.Left,
semanticModel,
cancellationToken);
}
else if (binaryExpression.Kind() == SyntaxKind.EqualsExpression &&
binaryExpression.Right.Kind() == SyntaxKind.NumericLiteralExpression)
{
canSimplify = CanSimplifyToLengthEqualsZeroExpression(
binaryExpression.Left,
(LiteralExpressionSyntax)binaryExpression.Right,
semanticModel,
cancellationToken);
}
else if (binaryExpression.Kind() == SyntaxKind.EqualsExpression &&
binaryExpression.Left.Kind() == SyntaxKind.NumericLiteralExpression)
{
canSimplify = CanSimplifyToLengthEqualsZeroExpression(
binaryExpression.Right,
(LiteralExpressionSyntax)binaryExpression.Left,
semanticModel,
cancellationToken);
}
return canSimplify;
}
示例12: BindSimpleBinaryOperator
private BoundExpression BindSimpleBinaryOperator(BinaryExpressionSyntax node, DiagnosticBag diagnostics)
{
// The simple binary operators are left-associative, and expressions of the form
// a + b + c + d .... are relatively common in machine-generated code. The parser can handle
// creating a deep-on-the-left syntax tree no problem, and then we promptly blow the stack during
// semantic analysis. Here we build an explicit stack to handle the left-hand recursion.
Debug.Assert(IsSimpleBinaryOperator(node.Kind()));
var syntaxNodes = ArrayBuilder<BinaryExpressionSyntax>.GetInstance();
ExpressionSyntax current = node;
while (IsSimpleBinaryOperator(current.Kind()))
{
var binOp = (BinaryExpressionSyntax)current;
syntaxNodes.Push(binOp);
current = binOp.Left;
}
int compoundStringLength = 0;
BoundExpression result = BindExpression(current, diagnostics);
if (node.IsKind(SyntaxKind.SubtractExpression)
&& current.IsKind(SyntaxKind.ParenthesizedExpression))
{
if (result.Kind == BoundKind.TypeExpression
&& !((ParenthesizedExpressionSyntax)current).Expression.IsKind(SyntaxKind.ParenthesizedExpression))
{
Error(diagnostics, ErrorCode.ERR_PossibleBadNegCast, node);
}
else if (result.Kind == BoundKind.BadExpression)
{
var parenthesizedExpression = (ParenthesizedExpressionSyntax) current;
if (parenthesizedExpression.Expression.IsKind(SyntaxKind.IdentifierName)
&& ((IdentifierNameSyntax) parenthesizedExpression.Expression).Identifier.ValueText == "dynamic")
{
Error(diagnostics, ErrorCode.ERR_PossibleBadNegCast, node);
}
}
}
while (syntaxNodes.Count > 0)
{
BinaryExpressionSyntax syntaxNode = syntaxNodes.Pop();
BindValueKind bindValueKind = GetBinaryAssignmentKind(syntaxNode.Kind());
BoundExpression left = CheckValue(result, bindValueKind, diagnostics);
BoundExpression right = BindValue(syntaxNode.Right, diagnostics, BindValueKind.RValue);
BoundExpression boundOp = BindSimpleBinaryOperator(syntaxNode, diagnostics, left, right, ref compoundStringLength);
result = boundOp;
}
syntaxNodes.Free();
return result;
}