protected override System.Type GetResultType(System.Type leftType, System.Type rightType) { Type binaryResultType = ImplicitConverter.GetBinaryResultType(leftType, rightType); MethodInfo overloadedMethod = this.GetOverloadedArithmeticOperator(); // Is an overloaded operator defined for our left and right children? if ((overloadedMethod != null)) { // Yes, so use its return type return(overloadedMethod.ReturnType); } else if ((binaryResultType != null)) { // Operands are primitive types. Return computed result type unless we are doing a power operation if (MyOperation == BinaryArithmeticOperation.Power) { return(typeof(double)); } else { return(binaryResultType); } } else if (this.IsEitherChildOfType(typeof(string)) == true & (MyOperation == BinaryArithmeticOperation.Add)) { // String concatenation return(typeof(string)); } else { // Invalid types return(null); } }
public static Type GetBitwiseOpType(Type leftType, Type rightType) { if (IsIntegralType(leftType) == false || IsIntegralType(rightType) == false) { return(null); } else { return(ImplicitConverter.GetBinaryResultType(leftType, rightType)); } }
public override void Emit(FleeILGenerator ilg, IServiceProvider services) { Type binaryResultType = ImplicitConverter.GetBinaryResultType(MyLeftChild.ResultType, MyRightChild.ResultType); MethodInfo overloadedOperator = this.GetOverloadedCompareOperator(); if (this.AreBothChildrenOfType(typeof(string))) { // String equality MyLeftChild.Emit(ilg, services); MyRightChild.Emit(ilg, services); EmitStringEquality(ilg, MyOperation, services); } else if ((overloadedOperator != null)) { base.EmitOverloadedOperatorCall(overloadedOperator, ilg, services); } else if ((binaryResultType != null)) { // Emit a compare of numeric operands EmitChildWithConvert(MyLeftChild, binaryResultType, ilg, services); EmitChildWithConvert(MyRightChild, binaryResultType, ilg, services); EmitCompareOperation(ilg, MyOperation); } else if (this.AreBothChildrenOfType(typeof(bool))) { // Boolean equality this.EmitRegular(ilg, services); } else if (this.AreBothChildrenReferenceTypes() == true) { // Reference equality this.EmitRegular(ilg, services); } else if (MyLeftChild.ResultType.IsEnum == true & MyRightChild.ResultType.IsEnum == true) { this.EmitRegular(ilg, services); } else { Debug.Fail("unknown operand types"); } }
protected override System.Type GetResultType(System.Type leftType, System.Type rightType) { Type binaryResultType = ImplicitConverter.GetBinaryResultType(leftType, rightType); MethodInfo overloadedOperator = this.GetOverloadedCompareOperator(); bool isEqualityOp = IsOpTypeEqualOrNotEqual(MyOperation); // Use our string equality instead of overloaded operator if (object.ReferenceEquals(leftType, typeof(string)) & object.ReferenceEquals(rightType, typeof(string)) & isEqualityOp == true) { // String equality return(typeof(bool)); } else if ((overloadedOperator != null)) { return(overloadedOperator.ReturnType); } else if ((binaryResultType != null)) { // Comparison of numeric operands return(typeof(bool)); } else if (object.ReferenceEquals(leftType, typeof(bool)) & object.ReferenceEquals(rightType, typeof(bool)) & isEqualityOp == true) { // Boolean equality return(typeof(bool)); } else if (this.AreBothChildrenReferenceTypes() == true & isEqualityOp == true) { // Comparison of reference types return(typeof(bool)); } else if (this.AreBothChildrenSameEnum() == true) { return(typeof(bool)); } else { // Invalid operands return(null); } }