本文整理汇总了C#中BinaryExpressionSyntax.CSharpKind方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpressionSyntax.CSharpKind方法的具体用法?C# BinaryExpressionSyntax.CSharpKind怎么用?C# BinaryExpressionSyntax.CSharpKind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryExpressionSyntax
的用法示例。
在下文中一共展示了BinaryExpressionSyntax.CSharpKind方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InferTypeInBinaryExpression
private IEnumerable<ITypeSymbol> InferTypeInBinaryExpression(BinaryExpressionSyntax binop, ExpressionSyntax expressionOpt = null, SyntaxToken? previousToken = null)
{
// If we got here through a token, then it must have actually been the binary
// operator's token.
Contract.ThrowIfTrue(previousToken.HasValue && previousToken.Value != binop.OperatorToken);
if (binop.CSharpKind() == SyntaxKind.CoalesceExpression)
{
return InferTypeInCoalesceExpression(binop, expressionOpt, previousToken);
}
var onRightOfToken = binop.Right == expressionOpt || previousToken.HasValue;
switch (binop.OperatorToken.CSharpKind())
{
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
case SyntaxKind.LessThanLessThanEqualsToken:
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
if (onRightOfToken)
{
// x << Foo(), x >> Foo(), x <<= Foo(), x >>= Foo()
return SpecializedCollections.SingletonEnumerable(this.Compilation.GetSpecialType(SpecialType.System_Int32));
}
break;
}
// Infer operands of && and || as bool regardless of the other operand.
if (binop.OperatorToken.CSharpKind() == SyntaxKind.AmpersandAmpersandToken ||
binop.OperatorToken.CSharpKind() == SyntaxKind.BarBarToken)
{
return SpecializedCollections.SingletonEnumerable(this.Compilation.GetSpecialType(SpecialType.System_Boolean));
}
// Try to figure out what's on the other side of the binop. If we can, then just that
// type. This is often a reasonable heuristics to use for most operators. NOTE(cyrusn):
// we could try to bind the token to see what overloaded operators it corresponds to.
// But the gain is pretty marginal IMO.
var otherSide = onRightOfToken ? binop.Left : binop.Right;
var otherSideTypes = GetTypes(otherSide);
if (otherSideTypes.Any())
{
return otherSideTypes;
}
// For &, &=, |, |=, ^, and ^=, since we couldn't infer the type of either side,
// try to infer the type of the entire binary expression.
if (binop.OperatorToken.CSharpKind() == SyntaxKind.AmpersandToken ||
binop.OperatorToken.CSharpKind() == SyntaxKind.AmpersandEqualsToken ||
binop.OperatorToken.CSharpKind() == SyntaxKind.BarToken ||
binop.OperatorToken.CSharpKind() == SyntaxKind.BarEqualsToken ||
binop.OperatorToken.CSharpKind() == SyntaxKind.CaretToken ||
binop.OperatorToken.CSharpKind() == SyntaxKind.CaretEqualsToken)
{
var parentTypes = InferTypes(binop);
if (parentTypes.Any())
{
return parentTypes;
}
}
// If it's a plus operator, then do some smarts in case it might be a string or
// delegate.
if (binop.OperatorToken.CSharpKind() == SyntaxKind.PlusToken)
{
// See Bug 6045. Note: we've already checked the other side of the operator. So this
// is the case where the other side was also unknown. So we walk one higher and if
// we get a delegate or a string type, then use that type here.
var parentTypes = InferTypes(binop);
if (parentTypes.Any(parentType => parentType.SpecialType == SpecialType.System_String || parentType.TypeKind == TypeKind.Delegate))
{
return parentTypes.Where(parentType => parentType.SpecialType == SpecialType.System_String || parentType.TypeKind == TypeKind.Delegate);
}
}
// Otherwise pick some sane defaults for certain common cases.
switch (binop.OperatorToken.CSharpKind())
{
case SyntaxKind.BarToken:
case SyntaxKind.CaretToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.LessThanToken:
case SyntaxKind.LessThanEqualsToken:
case SyntaxKind.GreaterThanToken:
case SyntaxKind.GreaterThanEqualsToken:
case SyntaxKind.PlusToken:
case SyntaxKind.MinusToken:
case SyntaxKind.AsteriskToken:
case SyntaxKind.SlashToken:
case SyntaxKind.PercentToken:
case SyntaxKind.CaretEqualsToken:
case SyntaxKind.PlusEqualsToken:
case SyntaxKind.MinusEqualsToken:
case SyntaxKind.AsteriskEqualsToken:
case SyntaxKind.SlashEqualsToken:
case SyntaxKind.PercentEqualsToken:
case SyntaxKind.LessThanLessThanToken:
case SyntaxKind.GreaterThanGreaterThanToken:
//.........这里部分代码省略.........
示例2: VisitBinaryExpression
public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
{
bool isOrAsNode = node.CSharpKind() == SyntaxKind.AsExpression || node.CSharpKind() == 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;
}
示例3: ResolveAssignmentExpression
public FlatOperand ResolveAssignmentExpression(BinaryExpressionSyntax node, TypeInfo result_type, FlatOperand into_lvalue, FlatOperand parent_op, List<FlatStatement> instructions)
{
FlatOperand fop_result;
FlatOperand lvalue_result;
FlatOperand fop_subject;
FlatOperand fop_type;
if (node.Left is ElementAccessExpressionSyntax)
{
ElementAccessExpressionSyntax eaes = (ElementAccessExpressionSyntax)node.Left;
fop_subject = ResolveExpression(eaes.Expression, null, instructions);
FlatOperand fop_right = ResolveExpression(node.Right, into_lvalue, instructions);
List<FlatOperand> args = ResolveArguments(eaes.ArgumentList, instructions);
FlatOperand key = ArrayIndexFrom(args, instructions);
instructions.Add(FlatStatement.ARRAYSET(fop_subject, key, fop_right));
return fop_right;
}
SymbolInfo si = Model.GetSymbolInfo(node.Left);
switch (si.Symbol.Kind)
{
case SymbolKind.Event:
{
fop_subject = ResolveParentExpression(si, node.Left, null, parent_op, instructions);
fop_type = Resolve(si.Symbol.ContainingType, null, instructions);
//TypeOf(fop_subject, null, null, instructions);
FlatOperand fop_Field;
// ITypeSymbol typeSymbol;
IEventSymbol ps = (IEventSymbol)si.Symbol;
{
/*
if (ps.IsStatic)
{
fop_Field = Resolve(ps, fop_type, null, instructions);
}
else/**/
{
//typeSymbol = ps.Type;
fop_Field = Resolve(ps, fop_type, null, instructions);
}
}
FlatOperand fop_right = ResolveExpression(node.Right, into_lvalue, instructions);
if (node.CSharpKind() == SyntaxKind.SimpleAssignmentExpression)
{
fop_result = fop_right;
}
else
{
fop_result = AllocateRegister("");
lvalue_result = fop_result.GetLValue(this, instructions);
if (ps.IsStatic)
{
instructions.Add(FlatStatement.GETSTATICFIELD(lvalue_result, fop_Field));
}
else
{
instructions.Add(FlatStatement.GETFIELD(lvalue_result, fop_Field, fop_subject));
}
ResolveBinaryExpression(node.CSharpKind(), fop_result, fop_right, lvalue_result, instructions);
}
if (ps.IsStatic)
{
instructions.Add(FlatStatement.SETSTATICFIELD(fop_Field, fop_result));
}
else
{
instructions.Add(FlatStatement.SETFIELD(fop_Field, fop_subject, fop_result));
}
return fop_result;
}
break;
case SymbolKind.Field:
{
fop_subject = ResolveParentExpression(si, node.Left, null, parent_op, instructions);
fop_type = Resolve(si.Symbol.ContainingType, null, instructions);
//TypeOf(fop_subject, null, null, instructions);
FlatOperand fop_Field;
// ITypeSymbol typeSymbol;
IFieldSymbol ps = (IFieldSymbol)si.Symbol;
{
/*
if (ps.IsStatic)
{
fop_Field = Resolve(ps, fop_type, null, instructions);
}
else/**/
{
//typeSymbol = ps.Type;
fop_Field = Resolve(ps, fop_type, null, instructions);
}
}
//.........这里部分代码省略.........
示例4: ResolveExpression
public FlatOperand ResolveExpression(BinaryExpressionSyntax node, TypeInfo result_type, FlatOperand into_lvalue, FlatOperand parent_op, List<FlatStatement> instructions)
{
if (node.IsAssignment())
{
return ResolveAssignmentExpression(node, result_type, into_lvalue, parent_op, instructions);
}
FlatOperand left = ResolveExpression(node.Left, null, instructions);
FlatOperand right = ResolveExpression(node.Right, null, instructions);
return ResolveBinaryExpression(node.CSharpKind(), left, right, into_lvalue, instructions);
}
示例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.CSharpKind() == SyntaxKind.GreaterThanExpression || node.CSharpKind() == SyntaxKind.RightShiftExpression) && !node.IsParentKind(SyntaxKind.ParenthesizedExpression))
{
return result.Parenthesize();
}
return result;
}