static bool IsArithmetic(IBinaryOperation op) { return(op.OperatorKind is BinaryOperatorKind.Add or BinaryOperatorKind.Subtract or BinaryOperatorKind.Multiply or BinaryOperatorKind.Divide); }
/// <summary> /// Returns true if the binaryExpression consists of an expression that can never be negative, /// such as length or unsigned numeric types, being compared to zero with greater than, /// less than, or equals relational operator. /// </summary> public static bool IsSpecialCaseBinaryExpression( IBinaryOperation binaryOperation, BinaryOperatorKind operationKind) { if (binaryOperation == null) { return(false); } var rightOperand = RemoveImplicitConversion(binaryOperation.RightOperand); var leftOperand = RemoveImplicitConversion(binaryOperation.LeftOperand); switch (operationKind) { case BinaryOperatorKind.LessThanOrEqual when rightOperand.IsNumericLiteral(): return(CanSimplifyToLengthEqualsZeroExpression( leftOperand, (ILiteralOperation)rightOperand)); case BinaryOperatorKind.GreaterThanOrEqual when leftOperand.IsNumericLiteral(): return(CanSimplifyToLengthEqualsZeroExpression( rightOperand, (ILiteralOperation)leftOperand)); } return(false); }
public override IOperation VisitBinaryOperator(IBinaryOperation operation, object argument) { return(new BinaryOperation(operation.OperatorKind, Visit(operation.LeftOperand), Visit(operation.RightOperand), operation.IsLifted, operation.IsChecked, operation.IsCompareText, operation.OperatorMethod, ((BaseBinaryOperation)operation).UnaryOperatorMethod, ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit)); }
private static IExpression InvertBinaryOperation(IBinaryOperation binOp) { BinaryOperation /*?*/ result = null; if (binOp is IEquality && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float32 && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float64) { result = new NotEquality(); } else if (binOp is INotEquality && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float32 && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float64) { result = new Equality(); } else if (binOp is ILessThan) { result = new GreaterThanOrEqual() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((ILessThan)binOp).IsUnsignedOrUnordered, binOp) } } ; else if (binOp is ILessThanOrEqual) { result = new GreaterThan() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((ILessThanOrEqual)binOp).IsUnsignedOrUnordered, binOp) } } ; else if (binOp is IGreaterThan) { result = new LessThanOrEqual() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((IGreaterThan)binOp).IsUnsignedOrUnordered, binOp) } } ; else if (binOp is IGreaterThanOrEqual) { result = new LessThan() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((IGreaterThanOrEqual)binOp).IsUnsignedOrUnordered, binOp) } } ; if (result != null) { result.LeftOperand = binOp.LeftOperand; result.RightOperand = binOp.RightOperand; result.Type = binOp.Type; result.Locations.AddRange(binOp.Locations); return(result); } LogicalNot logicalNot = new LogicalNot(); logicalNot.Operand = binOp; logicalNot.Type = binOp.Type; logicalNot.Locations.AddRange(binOp.Locations); return(logicalNot); }
public override bool VisitBinaryOperator([NotNull] IBinaryOperation operation1, [CanBeNull] IOperation argument) { return(argument is IBinaryOperation operation2 && AreBaseOperationsEqual(operation1, operation2) && operation1.OperatorKind == operation2.OperatorKind && AreSymbolsEqual(operation1.OperatorMethod, operation2.OperatorMethod) && operation1.IsLifted == operation2.IsLifted && operation1.IsChecked == operation2.IsChecked && operation1.IsCompareText == operation2.IsCompareText); }
private ITypeReference GetBitwiseOperationType(IBinaryOperation binaryOperation) { if (binaryOperation.LeftOperand.Type.TypeCode == PrimitiveTypeCode.Boolean && binaryOperation.RightOperand.Type.TypeCode == PrimitiveTypeCode.Boolean) { return(this.platformType.SystemBoolean); } return(this.GetBinaryNumericOperationType(binaryOperation)); }
protected static IInvocationOperation GetInvocation(IBinaryOperation violation) { var result = UseStringEqualsOverStringCompare.GetInvocationFromEqualityCheckWithLiteralZero(violation); RoslynDebug.Assert(result is not null); return(result); }
public static int AccumulateWI(int[] arr, int result, IBinaryOperation bp) { for (int i = 0; i != arr.Length; ++i) { result = bp.Call(result, arr[i]); } return(result); }
public string Clear() { Lhs.Reset(); Rhs.Reset(); pending_operation = null; equals_flag = false; return("Clear"); }
internal static ImmutableArray <IOperation> FlattenBinaryOperation(IBinaryOperation root) { var walker = new BinaryOperandWalker(); walker.Visit(root); return(walker.Operands.ToImmutable()); }
public override void Visit(IBinaryOperation binaryOperation) { if (Process(binaryOperation)) { visitor.Visit(binaryOperation); } base.Visit(binaryOperation); }
private static ConstantResult DetermineConstant(IBinaryOperation op) { return((op.LeftOperand, op.RightOperand) switch { var(_, v) when IsConstant(v) => ConstantResult.Right, var(v, _) when IsConstant(v) => ConstantResult.Left, _ => ConstantResult.None, });
/// <summary> /// Check to see if we have an expression comparing the result of /// <see cref="System.Linq.Enumerable.Count{TSource}(System.Collections.Generic.IEnumerable{TSource})"/> or /// <see cref="System.Linq.Enumerable.Count{TSource}(System.Collections.Generic.IEnumerable{TSource}, Func{TSource, bool})"/> /// using operators. /// </summary> private static void AnalyzeBinaryExpression(IBinaryOperation binaryOperation, INamedTypeSymbol enumerableType, Action <Diagnostic> reportDiagnostic) { if (binaryOperation.IsComparisonOperator() && (IsLeftCountComparison(binaryOperation, enumerableType) || IsRightCountComparison(binaryOperation, enumerableType))) { reportDiagnostic(binaryOperation.Syntax.CreateDiagnostic(s_rule)); } }
public string Clear_entered() { pending_operation = null; unary_operation = null; firstEnteredValue = 0.0; lastEnteredValue = 0.0; return("0"); }
public override void VisitBinaryOperator([NotNull] IBinaryOperation operation) { NullCheckScanResult?scanResult = scanner.ScanBinaryOperator(operation); SetScanResult(scanResult); base.VisitBinaryOperator(operation); }
public string Equals() { if (pending_operation != null) { lhs = pending_operation.Perform_binary_calculation(lhs, rhs); pending_operation = null; } return(lhs.ToString()); }
public override void VisitBinaryOperator(IBinaryOperation operation) { var operatorMethod = operation.OperatorMethod; var binaryOperationKind = operation.OperatorKind; var isLifted = operation.IsLifted; var isChecked = operation.IsChecked; var isCompareText = operation.IsCompareText; base.VisitBinaryOperator(operation); }
private static bool KeepUnsignedButInvertUnordered(bool usignedOrUnordered, IBinaryOperation binOp) { var isIntegerOperation = TypeHelper.IsPrimitiveInteger(binOp.LeftOperand.Type); if (usignedOrUnordered) { return(isIntegerOperation); } return(!isIntegerOperation); //i.e. !(x < y) is the same as (x >= y) only if first comparison returns the opposite result than the second for the unordered case. }
private static SyntaxNode NewBinaryOperation( IBinaryOperation binaryOperation, SyntaxNode leftOperand, BinaryOperatorKind operationKind, SyntaxNode rightOperand, SyntaxGenerator generator ) { switch (operationKind) { case BinaryOperatorKind.Equals: return (binaryOperation.LeftOperand.Type?.IsValueType == true && binaryOperation.RightOperand.Type?.IsValueType == true ? generator.ValueEqualsExpression(leftOperand, rightOperand) : generator.ReferenceEqualsExpression(leftOperand, rightOperand)); case BinaryOperatorKind.NotEquals: return (binaryOperation.LeftOperand.Type?.IsValueType == true && binaryOperation.RightOperand.Type?.IsValueType == true ? generator.ValueNotEqualsExpression(leftOperand, rightOperand) : generator.ReferenceNotEqualsExpression(leftOperand, rightOperand)); case BinaryOperatorKind.LessThanOrEqual: return(IsSpecialCaseBinaryExpression(binaryOperation, operationKind) ? generator.ValueEqualsExpression(leftOperand, rightOperand) : generator.LessThanOrEqualExpression(leftOperand, rightOperand)); case BinaryOperatorKind.GreaterThanOrEqual: return(IsSpecialCaseBinaryExpression(binaryOperation, operationKind) ? generator.ValueEqualsExpression(leftOperand, rightOperand) : generator.GreaterThanOrEqualExpression(leftOperand, rightOperand)); case BinaryOperatorKind.LessThan: return(generator.LessThanExpression(leftOperand, rightOperand)); case BinaryOperatorKind.GreaterThan: return(generator.GreaterThanExpression(leftOperand, rightOperand)); case BinaryOperatorKind.Or: return(generator.BitwiseOrExpression(leftOperand, rightOperand)); case BinaryOperatorKind.And: return(generator.BitwiseAndExpression(leftOperand, rightOperand)); case BinaryOperatorKind.ConditionalOr: return(generator.LogicalOrExpression(leftOperand, rightOperand)); case BinaryOperatorKind.ConditionalAnd: return(generator.LogicalAndExpression(leftOperand, rightOperand)); } return(null); }
public string Clear_entered() { lhs = 0; rhs = 0; result = "0"; is_num_entered = false; is_decimal_entered = false; binary_pending_operation = null; unary_pending_operation = null; return(result); }
private static AbstractExpression ReadBinaryOperator(IBinaryOperation op) { var context = CodeReaderContext.GetContextOrThrow(); return(new BinaryExpression { Left = ReadExpression(op.LeftOperand), Right = ReadExpression(op.RightOperand), Type = context.CodeModel.TryGet <TypeMember>(op.Type), Operator = BinaryOperatorByOperatorKind[op.OperatorKind] }); }
private ITypeReference GetBitwiseOperationType(IBinaryOperation binaryOperation) { Contract.Requires(binaryOperation != null); Contract.Ensures(Contract.Result <ITypeReference>() != null); if (binaryOperation.LeftOperand.Type.TypeCode == PrimitiveTypeCode.Boolean && binaryOperation.RightOperand.Type.TypeCode == PrimitiveTypeCode.Boolean) { return(this.platformType.SystemBoolean); } return(this.GetBinaryNumericOperationType(binaryOperation)); }
private ITypeReference GetBinaryNumericOperationType(IBinaryOperation binaryOperation, bool operandsAreTreatedAsUnsigned) { Contract.Requires(binaryOperation != null); var result = this.GetBinaryNumericOperationType(binaryOperation); if (operandsAreTreatedAsUnsigned) { result = TypeHelper.UnsignedEquivalent(result); } return(result); }
public override SyntaxNode CreateReplacementExpression(IBinaryOperation violation, SyntaxGenerator generator) { RoslynDebug.Assert(IsMatch(violation)); var invocation = GetInvocation(violation); var equalsInvocationSyntax = generator.InvocationExpression( CreateEqualsMemberAccess(generator), invocation.Arguments.GetArgumentsInParameterOrder().Select(x => x.Value.Syntax)); return(InvertIfNotEquals(equalsInvocationSyntax, violation, generator)); }
public static int FindIf(int[] arr, IBinaryOperation bo) { for (int i = 0; i != arr.Length; ++i) { if (bo.Call(arr[i])) { return(i); } } return(-1); }
/// <summary> /// Checks whether 0 or 1 is being compared with the value of the invocation of one of the <see cref="_targetMethodNames" /> in the <see cref="_targetType" /> /// using <see cref="int" /> comparison operators. /// </summary> /// <param name="binaryOperation">The binary operation.</param> /// <param name="methodName">If the value of the invocation of one of the <see cref="_targetMethodNames" /> in the <see cref="_targetType" />, contains the method name; <see langword="null"/> otherwise.</param> /// <returns><see langword="true" /> if 0 or 1 is being compared with the value of the invocation of one of the <see cref="_targetMethodNames" /> in the <see cref="_targetType" /> /// using <see cref="int" /> comparison operators; otherwise, <see langword="false" />.</returns> private bool IsRightCountComparison(IBinaryOperation binaryOperation, [NotNullWhen(returnValue: true)] out string?methodName, out bool shouldNegate) { methodName = null; shouldNegate = false; if (!TryGetZeroOrOneConstant(binaryOperation.LeftOperand, out var constant)) { return(false); } switch (constant) { case 0: switch (binaryOperation.OperatorKind) { case BinaryOperatorKind.Equals: case BinaryOperatorKind.LessThan: shouldNegate = true; break; case BinaryOperatorKind.NotEquals: case BinaryOperatorKind.GreaterThanOrEqual: shouldNegate = false; break; default: return(false); } break; case 1: switch (binaryOperation.OperatorKind) { case BinaryOperatorKind.LessThanOrEqual: shouldNegate = false; break; case BinaryOperatorKind.GreaterThan: shouldNegate = true; break; default: return(false); } break; default: return(false); } return(IsCountMethodInvocation(binaryOperation.RightOperand, out methodName)); }
internal object ApplyToRight(IBinaryOperation op, object value) { IList <object> values = new List <object>(); foreach (var element in this.elements) { values.Add(op.Apply(value, element)); } return(new Vector(values)); }
public override void VisitBinaryOperator(IBinaryOperation operation) { Assert.Equal(OperationKind.BinaryOperator, operation.Kind); var operatorMethod = operation.OperatorMethod; var binaryOperationKind = operation.OperatorKind; var isLifted = operation.IsLifted; var isChecked = operation.IsChecked; var isCompareText = operation.IsCompareText; AssertEx.Equal(new[] { operation.LeftOperand, operation.RightOperand }, operation.Children); }
public void ApplyEquality() { try { if (_isLastActionAnEquation && _lastBinaryOperation == null) { var newValue = _displayNumber.ToDouble(); DisplayValue = newValue.ToString(_cultureInfo); _lastOperand1 = newValue; return; } var binaryOperationInfo = GetBinaryOperationInfo(); if (binaryOperationInfo == null) { return; } var value1 = binaryOperationInfo.Value1; var value2 = binaryOperationInfo.Value2; var binaryOperation = binaryOperationInfo.BinaryOperation; var executableInfo = binaryOperation.GetExecutableInfo(value1, value2); if (executableInfo.CanBeExecuted) { var result = binaryOperation.Execute(value1, value2); var displayValue = result.ToString(_cultureInfo); _displayNumber = DisplayNumberFactory.Create(displayValue); DisplayValue = displayValue; _lastOperand1 = value1; _lastOperand2 = value2; _lastBinaryOperation = binaryOperation; } else { DisplayValue = executableInfo.Message; } _selectedBinaryOperation = null; } catch { DisplayValue = ErrorMessages.OperationFailed; } finally { _lastActionType = ActionType.Equality; _isLastActionAnBinaryOperation = false; _isLastActionAnEquation = true; } }
public override void VisitBinaryOperator(IBinaryOperation operation) { if (operation.OperatorKind == BinaryOperatorKind.NotEquals) { Visit(operation.RightOperand); if (isNullLiteralMatched) { Visit(operation.LeftOperand); } } }
static void ComplexNumberBinaryArithmetics(IBinaryOperation channel, Complex z1, Complex z2) { try { Console.WriteLine("\n*** Complex Number Binary Arithmetics ***\n"); Console.WriteLine("{0} + {1} = {2}", f(z1), f(z2), f(channel.Add(z1, z2))); Console.WriteLine("{0} - {1} = {2}", f(z1), f(z2), f(channel.Subtract(z1, z2))); Console.WriteLine("{0} * {1} = {2}", f(z1), f(z2), f(channel.Multiply(z1, z2))); Console.WriteLine("{0} / {1} = {2}", f(z1), f(z2), f(channel.Divide(z1, z2))); } catch (Exception fx) { Console.WriteLine(fx.Message); } }
/// <summary> /// Performs some computation with the given bitwise and expression. /// </summary> /// <param name="binaryOperation"></param> public virtual void Visit(IBinaryOperation binaryOperation) { this.Visit((IExpression)binaryOperation); }
/// <summary> /// Called whenever a binary operation expression is about to be traversed by a type specific routine. /// This gives the traverser the opportunity to take some uniform action for all binary operation expressions, /// regardless of how the traversal gets to them. /// </summary> public virtual void TraverseChildren(IBinaryOperation binaryOperation) { Contract.Requires(binaryOperation != null); this.TraverseChildren((IExpression)binaryOperation); this.Traverse(binaryOperation.LeftOperand); this.Traverse(binaryOperation.RightOperand); }
/// <summary> /// Traverses the bitwise and expression. /// </summary> /// <param name="binaryOperation"></param> public void Traverse(IBinaryOperation binaryOperation) { Contract.Requires(binaryOperation != null); binaryOperation.Dispatch(this.dispatchingVisitor); }
/// <summary> /// Rewrites the given bitwise and expression. /// </summary> /// <param name="binaryOperation"></param> public virtual IExpression Rewrite(IBinaryOperation binaryOperation) { binaryOperation.Dispatch(this.dispatchingVisitor); return (IBinaryOperation)this.dispatchingVisitor.result; }
/// <summary> /// /// </summary> /// <param name="binaryOperation"></param> internal BinaryOperation(IBinaryOperation binaryOperation) : base(binaryOperation) { this.leftOperand = binaryOperation.LeftOperand; this.rightOperand = binaryOperation.RightOperand; this.resultIsUnmodifiedLeftOperand = binaryOperation.ResultIsUnmodifiedLeftOperand; }
/// <summary> /// Rewrites the given bitwise and expression. /// </summary> /// <param name="binaryOperation"></param> public virtual IExpression Rewrite(IBinaryOperation binaryOperation) { return binaryOperation; }
public override void TraverseChildren(IBinaryOperation binaryOperation) { base.TraverseChildren(binaryOperation); if (binaryOperation.LeftOperand.Type.TypeCode == PrimitiveTypeCode.Char) { if (binaryOperation.RightOperand.Type.TypeCode == PrimitiveTypeCode.Int32) ((BinaryOperation)binaryOperation).RightOperand = new Conversion() { ValueToConvert = binaryOperation.RightOperand, Type = binaryOperation.LeftOperand.Type, TypeAfterConversion = binaryOperation.LeftOperand.Type }; } else if (binaryOperation.RightOperand.Type.TypeCode == PrimitiveTypeCode.Char) { if (binaryOperation.LeftOperand.Type.TypeCode == PrimitiveTypeCode.Int32) ((BinaryOperation)binaryOperation).LeftOperand = new Conversion() { ValueToConvert = binaryOperation.LeftOperand, Type = binaryOperation.RightOperand.Type, TypeAfterConversion = binaryOperation.RightOperand.Type }; } }
/// <summary> /// /// </summary> /// <param name="binaryOperation"></param> internal BinaryOperation(IBinaryOperation binaryOperation) : base(binaryOperation) { this.leftOperand = binaryOperation.LeftOperand; this.rightOperand = binaryOperation.RightOperand; }
private ITypeReference GetBitwiseOperationType(IBinaryOperation binaryOperation) { if (binaryOperation.LeftOperand.Type.TypeCode == PrimitiveTypeCode.Boolean && binaryOperation.RightOperand.Type.TypeCode == PrimitiveTypeCode.Boolean) return this.platformType.SystemBoolean; return this.GetBinaryNumericOperationType(binaryOperation); }
/// <summary> /// Performs some computation with the given bitwise and expression. /// </summary> /// <param name="binaryOperation"></param> public virtual void Visit(IBinaryOperation binaryOperation) { }
private static bool KeepUnsignedButInvertUnordered(bool usignedOrUnordered, IBinaryOperation binOp) { Contract.Requires(binOp != null); var isIntegerOperation = TypeHelper.IsPrimitiveInteger(binOp.LeftOperand.Type); if (usignedOrUnordered) return isIntegerOperation; return !isIntegerOperation; //i.e. !(x < y) is the same as (x >= y) only if first comparison returns the opposite result than the second for the unordered case. }
private static IExpression InvertBinaryOperation(IBinaryOperation binOp) { Contract.Requires(binOp != null); Contract.Ensures(Contract.Result<IExpression>() != null); BinaryOperation/*?*/ result = null; if (binOp is IEquality && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float32 && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float64) result = new NotEquality(); else if (binOp is INotEquality && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float32 && binOp.LeftOperand.Type.TypeCode != PrimitiveTypeCode.Float64) result = new Equality(); else if (binOp is ILessThan) result = new GreaterThanOrEqual() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((ILessThan)binOp).IsUnsignedOrUnordered, binOp) }; else if (binOp is ILessThanOrEqual) result = new GreaterThan() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((ILessThanOrEqual)binOp).IsUnsignedOrUnordered, binOp) }; else if (binOp is IGreaterThan) result = new LessThanOrEqual() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((IGreaterThan)binOp).IsUnsignedOrUnordered, binOp) }; else if (binOp is IGreaterThanOrEqual) result = new LessThan() { IsUnsignedOrUnordered = KeepUnsignedButInvertUnordered(((IGreaterThanOrEqual)binOp).IsUnsignedOrUnordered, binOp) }; if (result != null) { result.LeftOperand = binOp.LeftOperand; result.RightOperand = binOp.RightOperand; result.Type = binOp.Type; result.Locations.AddRange(binOp.Locations); return result; } LogicalNot logicalNot = new LogicalNot(); logicalNot.Operand = binOp; logicalNot.Type = binOp.Type; logicalNot.Locations.AddRange(binOp.Locations); return logicalNot; }
private ITypeReference GetBinaryNumericOperationType(IBinaryOperation binaryOperation) { Contract.Requires(binaryOperation != null); Contract.Ensures(Contract.Result<ITypeReference>() != null); var leftOperand = binaryOperation.LeftOperand; var rightOperand = binaryOperation.RightOperand; PrimitiveTypeCode leftTypeCode = leftOperand.Type.TypeCode; PrimitiveTypeCode rightTypeCode = rightOperand.Type.TypeCode; switch (leftTypeCode) { case PrimitiveTypeCode.Boolean: case PrimitiveTypeCode.Char: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt8: switch (rightTypeCode) { case PrimitiveTypeCode.Boolean: case PrimitiveTypeCode.Char: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt8: return this.platformType.SystemUInt32; case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: return this.platformType.SystemUInt32; //code generators will tend to make both operands be of the same type. Assume this happened because the right operand is a polymorphic constant. //The cases below are not expected to happen in practice case PrimitiveTypeCode.UInt64: case PrimitiveTypeCode.Int64: return this.platformType.SystemUInt64; case PrimitiveTypeCode.UIntPtr: case PrimitiveTypeCode.IntPtr: return this.platformType.SystemUIntPtr; case PrimitiveTypeCode.Float32: return this.platformType.SystemFloat32; case PrimitiveTypeCode.Float64: return this.platformType.SystemFloat64; default: return rightOperand.Type; //code generators will tend to make both operands be of the same type. Assume this happened because the right operand is an enum. } case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: switch (rightTypeCode) { case PrimitiveTypeCode.Boolean: case PrimitiveTypeCode.Char: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt8: return this.platformType.SystemUInt32; //code generators will tend to make both operands be of the same type. Assume this happened because the left operand is a polymorphic constant. case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: return this.platformType.SystemInt32; //The cases below are not expected to happen in practice case PrimitiveTypeCode.UInt64: return this.platformType.SystemUInt64; case PrimitiveTypeCode.Int64: return this.platformType.SystemInt64; case PrimitiveTypeCode.UIntPtr: return this.platformType.SystemUIntPtr; case PrimitiveTypeCode.IntPtr: return this.platformType.SystemIntPtr; case PrimitiveTypeCode.Float32: return this.platformType.SystemFloat32; case PrimitiveTypeCode.Float64: return this.platformType.SystemFloat64; default: return rightOperand.Type; //code generators will tend to make both operands be of the same type. Assume this happened because the right operand is an enum. } case PrimitiveTypeCode.UInt64: switch (rightTypeCode) { case PrimitiveTypeCode.Boolean: case PrimitiveTypeCode.Char: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt8: case PrimitiveTypeCode.UInt64: return this.platformType.SystemUInt64; case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: case PrimitiveTypeCode.Int64: return this.platformType.SystemUInt64; //code generators will tend to make both operands be of the same type. Assume this happened because the right operand is a polymorphic constant. case PrimitiveTypeCode.UIntPtr: return this.platformType.SystemUIntPtr; case PrimitiveTypeCode.IntPtr: return this.platformType.SystemIntPtr; case PrimitiveTypeCode.Float32: return this.platformType.SystemFloat32; case PrimitiveTypeCode.Float64: return this.platformType.SystemFloat64; default: return rightOperand.Type; //code generators will tend to make both operands be of the same type. Assume this happened because the right operand is an enum. } case PrimitiveTypeCode.Int64: switch (rightTypeCode) { case PrimitiveTypeCode.Boolean: case PrimitiveTypeCode.Char: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt8: case PrimitiveTypeCode.UInt64: return this.platformType.SystemUInt64; //code generators will tend to make both operands be of the same type. Assume this happened because the left operand is a polymorphic constant. case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: case PrimitiveTypeCode.Int64: return this.platformType.SystemInt64; case PrimitiveTypeCode.UIntPtr: case PrimitiveTypeCode.IntPtr: return this.platformType.SystemIntPtr; case PrimitiveTypeCode.Float32: return this.platformType.SystemFloat32; case PrimitiveTypeCode.Float64: return this.platformType.SystemFloat64; default: return rightOperand.Type; //code generators will tend to make both operands be of the same type. Assume this happened because the right operand is an enum. } case PrimitiveTypeCode.UIntPtr: switch (rightTypeCode) { case PrimitiveTypeCode.Boolean: case PrimitiveTypeCode.Char: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt8: case PrimitiveTypeCode.UInt64: case PrimitiveTypeCode.UIntPtr: return this.platformType.SystemUIntPtr; case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: case PrimitiveTypeCode.Int64: case PrimitiveTypeCode.IntPtr: return this.platformType.SystemUIntPtr; case PrimitiveTypeCode.Float32: return this.platformType.SystemFloat32; case PrimitiveTypeCode.Float64: return this.platformType.SystemFloat64; case PrimitiveTypeCode.Pointer: case PrimitiveTypeCode.Reference: return rightOperand.Type; default: Contract.Assume(false); return Dummy.TypeReference; } case PrimitiveTypeCode.IntPtr: switch (rightTypeCode) { case PrimitiveTypeCode.Boolean: case PrimitiveTypeCode.Char: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt8: case PrimitiveTypeCode.UInt64: case PrimitiveTypeCode.UIntPtr: return this.platformType.SystemUIntPtr; case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: case PrimitiveTypeCode.Int64: case PrimitiveTypeCode.IntPtr: return this.platformType.SystemIntPtr; case PrimitiveTypeCode.Float32: return this.platformType.SystemFloat32; case PrimitiveTypeCode.Float64: return this.platformType.SystemFloat64; case PrimitiveTypeCode.Pointer: case PrimitiveTypeCode.Reference: return rightOperand.Type; default: Contract.Assume(false); return Dummy.TypeReference; } case PrimitiveTypeCode.Float32: case PrimitiveTypeCode.Float64: return rightOperand.Type; case PrimitiveTypeCode.Pointer: case PrimitiveTypeCode.Reference: switch (rightTypeCode) { case PrimitiveTypeCode.Pointer: case PrimitiveTypeCode.Reference: return this.platformType.SystemUIntPtr; case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: case PrimitiveTypeCode.Int64: case PrimitiveTypeCode.UInt8: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt64: case PrimitiveTypeCode.IntPtr: case PrimitiveTypeCode.UIntPtr: return leftOperand.Type; default: Contract.Assume(false); return Dummy.TypeReference; } default: switch (rightTypeCode) { case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: case PrimitiveTypeCode.Int64: case PrimitiveTypeCode.Boolean: case PrimitiveTypeCode.Char: case PrimitiveTypeCode.UInt8: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt64: //assume that the left operand has an enum type. return leftOperand.Type; } return leftOperand.Type; //assume they are both enums } }
public override void Visit(IBinaryOperation binaryOperation) { if(Process(binaryOperation)){visitor.Visit(binaryOperation);} base.Visit(binaryOperation); }
public override void TraverseChildren(IBinaryOperation binaryOperation) { MethodEnter(binaryOperation); base.TraverseChildren(binaryOperation); MethodExit(); }
private bool IsPrefix(IBinaryOperation binaryOperation) { Contract.Requires(binaryOperation != null); return binaryOperation.LeftOperand is ITargetExpression && ExpressionHelper.IsIntegralOne(binaryOperation.RightOperand) && !binaryOperation.ResultIsUnmodifiedLeftOperand; }
private ITypeReference GetBinaryNumericOperationType(IBinaryOperation binaryOperation, bool operandsAreTreatedAsUnsigned) { Contract.Requires(binaryOperation != null); var result = this.GetBinaryNumericOperationType(binaryOperation); if (operandsAreTreatedAsUnsigned) result = TypeHelper.UnsignedEquivalent(result); return result; }
private bool IsPostfix(IBinaryOperation binaryOperation) { return binaryOperation.LeftOperand is ITargetExpression && ExpressionHelper.IsIntegralOne(binaryOperation.RightOperand) && binaryOperation.ResultIsUnmodifiedLeftOperand; }
private ITypeReference GetBitwiseOperationType(IBinaryOperation binaryOperation) { Contract.Requires(binaryOperation != null); Contract.Ensures(Contract.Result<ITypeReference>() != null); if (binaryOperation.LeftOperand.Type.TypeCode == PrimitiveTypeCode.Boolean && binaryOperation.RightOperand.Type.TypeCode == PrimitiveTypeCode.Boolean) return this.platformType.SystemBoolean; return this.GetBinaryNumericOperationType(binaryOperation); }