Example #1
0
 private bool TryTransformTernary(ConditionExpression ternary, out Expression transformed)
 {
     transformed = null;
     V_2         = ternary.get_Then() as LiteralExpression;
     V_3         = ternary.get_Else() as LiteralExpression;
     if (V_2 != null && V_3 != null)
     {
         V_14 = false;
         V_15 = false;
         if (!String.op_Equality(V_2.get_ExpressionType().get_FullName(), "System.Int32") || !String.op_Equality(V_3.get_ExpressionType().get_FullName(), "System.Int32"))
         {
             if (String.op_Equality(V_2.get_ExpressionType().get_FullName(), "System.Boolean") && String.op_Equality(V_3.get_ExpressionType().get_FullName(), "System.Boolean"))
             {
                 V_18 = (Boolean)V_2.get_Value();
                 V_19 = (Boolean)V_3.get_Value();
                 if (!V_18 && V_19 || V_18 && !V_19)
                 {
                     V_14 = true;
                     if (!V_18 && V_19)
                     {
                         V_15 = true;
                     }
                 }
             }
         }
         else
         {
             V_16 = (Int32)V_2.get_Value();
             V_17 = (Int32)V_3.get_Value();
             if (V_16 == 0 && V_17 == 1 || V_16 == 1 && V_17 == 0)
             {
                 V_14 = true;
                 if (V_16 == 0 && V_17 == 1)
                 {
                     V_15 = true;
                 }
             }
         }
         if (V_14)
         {
             if (!V_15)
             {
                 transformed = this.Transform(ternary.get_Condition());
             }
             else
             {
                 transformed = this.Transform(Negator.Negate(ternary.get_Condition(), this.typeSystem));
             }
             return(true);
         }
     }
     if (V_2 == null)
     {
         if (V_3 == null)
         {
             V_20 = ternary.get_Then() as ExplicitCastExpression;
             V_21 = ternary.get_Else() as ExplicitCastExpression;
             if (V_20 == null || V_21 == null || !String.op_Equality(V_20.get_TargetType().get_FullName(), "System.Int32") || !String.op_Equality(V_20.get_Expression().get_ExpressionType().get_FullName(), "System.Boolean") || !String.op_Equality(V_21.get_TargetType().get_FullName(), "System.Int32") || !String.op_Equality(V_21.get_Expression().get_ExpressionType().get_FullName(), "System.Boolean"))
             {
                 return(false);
             }
             ternary.set_Then(V_20.get_Expression());
             ternary.set_Else(V_21.get_Expression());
             transformed = ternary;
             return(true);
         }
         V_0 = V_3;
         V_1 = false;
     }
     else
     {
         V_0 = V_2;
         V_1 = true;
     }
     if (!String.op_Equality(V_0.get_ExpressionType().get_FullName(), "System.Int32"))
     {
         if (!String.op_Equality(V_0.get_ExpressionType().get_FullName(), "System.Boolean"))
         {
             return(false);
         }
         V_4 = (Boolean)V_0.get_Value();
     }
     else
     {
         if ((Int32)V_0.get_Value() != 0)
         {
             stackVariable163 = true;
         }
         else
         {
             stackVariable163 = false;
         }
         V_4 = stackVariable163;
     }
     V_6 = null;
     V_7 = null;
     V_6 = this.Transform(ternary.get_Condition());
     if (!V_1)
     {
         V_8 = ternary.get_Then();
     }
     else
     {
         V_8 = ternary.get_Else();
     }
     V_9  = V_8 as ConditionExpression;
     V_10 = V_8 as ExplicitCastExpression;
     V_11 = null;
     V_12 = false;
     if (V_9 == null && V_10 == null || String.op_Inequality(V_10.get_TargetType().get_FullName(), "System.Int32") || String.op_Inequality(V_10.get_Expression().get_ExpressionType().get_FullName(), "System.Boolean") && !this.IsBinaryExpression(V_8, out V_11, out V_12) && String.op_Inequality(V_8.get_ExpressionType().get_FullName(), "System.Boolean"))
     {
         return(false);
     }
     V_13 = false;
     if (V_10 == null)
     {
         if (V_11 == null)
         {
             if (V_9 != null && this.TryTransformTernary(V_9, out V_7))
             {
                 V_13 = true;
             }
         }
         else
         {
             V_22 = TransformCatchClausesFilterExpressionStep.GetBinaryExpression(V_12, V_11);
             if (this.TryTransformBinary(V_22))
             {
                 V_7  = TransformCatchClausesFilterExpressionStep.GetResultExpression(V_12, V_11, V_22);
                 V_13 = true;
             }
         }
     }
     else
     {
         V_7  = V_10.get_Expression();
         V_13 = true;
     }
     if (!V_13)
     {
         V_7 = V_8;
     }
     if (V_6 == null || V_7 == null)
     {
         return(false);
     }
     if (!V_4)
     {
         V_5 = 12;
         if (V_1)
         {
             stackVariable97 = Negator.Negate(V_6, this.typeSystem);
         }
         else
         {
             stackVariable97 = V_6;
         }
         V_6 = stackVariable97;
     }
     else
     {
         V_5 = 11;
         if (V_1)
         {
             stackVariable111 = V_6;
         }
         else
         {
             stackVariable111 = Negator.Negate(V_6, this.typeSystem);
         }
         V_6 = stackVariable111;
     }
     transformed = new BinaryExpression(V_5, V_6, V_7, this.typeSystem, ternary.get_MappedInstructions(), false);
     return(true);
 }
Example #2
0
		public override ICodeNode VisitBinaryExpression(BinaryExpression expression)
		{
			expression.set_Left((Expression)this.Visit(expression.get_Left()));
			expression.set_Right((Expression)this.Visit(expression.get_Right()));
			V_0 = expression.get_Left().get_ExpressionType();
			V_0 = this.GetElementType(V_0);
			if (V_0 != null)
			{
				if (String.op_Equality(V_0.get_FullName(), this.typeSystem.get_Char().get_FullName()))
				{
					if (expression.get_Right().get_CodeNodeType() == 22)
					{
						if (this.IsArithmeticOperator(expression.get_Operator()))
						{
							expression.set_ExpressionType(this.typeSystem.get_Char());
							return expression;
						}
						if (expression.get_Right().get_HasType())
						{
							V_2 = this.GetElementType(expression.get_Right().get_ExpressionType());
							if (String.op_Equality(V_0.get_FullName(), V_2.get_FullName()))
							{
								return expression;
							}
						}
						V_1 = expression.get_Right() as LiteralExpression;
						expression.set_Right(this.GetLiteralExpression((char)((Int32)V_1.get_Value()), V_1.get_MappedInstructions()));
					}
					if (String.op_Inequality(this.GetElementType(expression.get_Right().get_ExpressionType()).get_FullName(), this.typeSystem.get_Char().get_FullName()))
					{
						if (expression.get_Right().get_CodeNodeType() != 31 || !String.op_Equality(expression.get_Right().get_ExpressionType().get_FullName(), this.typeSystem.get_UInt16().get_FullName()))
						{
							expression.set_Right(new ExplicitCastExpression(expression.get_Right(), this.typeSystem.get_Char(), null));
						}
						else
						{
							((ExplicitCastExpression)expression.get_Right()).set_TargetType(this.typeSystem.get_Char());
						}
					}
				}
				if (String.op_Equality(V_0.get_FullName(), this.typeSystem.get_Boolean().get_FullName()) && expression.get_Right().get_CodeNodeType() == 22)
				{
					if (expression.get_Operator() == 9 || expression.get_Operator() == 10 || this.IsBooleanAssignmentOperator(expression.get_Operator()))
					{
						V_3 = expression.get_Right() as LiteralExpression;
						V_4 = true;
						if (V_3.get_Value() == null || V_3.get_Value().Equals(0) || V_3.get_Value().Equals(false) || V_3.get_Value().Equals(null))
						{
							V_4 = false;
						}
						expression.set_Right(this.GetLiteralExpression(V_4, V_3.get_MappedInstructions()));
					}
					if (expression.get_Operator() == 9 || expression.get_Operator() == 10)
					{
						return this.SimplifyBooleanComparison(expression);
					}
				}
			}
			if (expression.get_Operator() == 9 || expression.get_Operator() == 10)
			{
				V_5 = this.GetElementType(expression.get_Right().get_ExpressionType());
				if (V_5 != null && V_0 != null && String.op_Inequality(V_5.get_FullName(), V_0.get_FullName()))
				{
					return this.FixEqualityComparisonExpression(expression);
				}
			}
			if (expression.get_IsAssignmentExpression())
			{
				if (!this.NeedsPointerCast(expression))
				{
					if (expression.get_Left().get_HasType() && expression.get_Left().get_ExpressionType().get_IsByReference() || expression.get_Left().get_ExpressionType().get_IsPointer() || expression.get_Left().get_ExpressionType().get_IsArray() || !expression.get_Left().get_ExpressionType().get_IsPrimitive())
					{
						V_6 = expression.get_Left().get_ExpressionType().Resolve();
						if (V_6 != null && !V_6.get_IsEnum() && expression.get_Right() as LiteralExpression != null)
						{
							V_7 = expression.get_Right() as LiteralExpression;
							if (V_7.get_Value() != null && V_7.get_Value().Equals(0))
							{
								expression.set_Right(new LiteralExpression(null, this.typeSystem, expression.get_Right().get_UnderlyingSameMethodInstructions()));
							}
						}
					}
				}
				else
				{
					if (expression.get_Right().get_CodeNodeType() != 45)
					{
						expression.set_Right(new ExplicitCastExpression(expression.get_Right(), expression.get_Left().get_ExpressionType(), null));
					}
					else
					{
						expression.get_Right().set_ExpressionType(expression.get_Left().get_ExpressionType());
					}
				}
			}
			if (expression.get_Operator() == 15 && expression.get_MappedInstructions().Count<Instruction>() == 1 && expression.get_MappedInstructions().First<Instruction>().get_OpCode().get_Code() == 194)
			{
				V_9 = null;
				if (expression.get_Right().get_CodeNodeType() != 22)
				{
					if (expression.get_Right().get_CodeNodeType() == 31)
					{
						V_10 = expression.get_Right() as ExplicitCastExpression;
						if (V_10.get_Expression().get_CodeNodeType() == 22)
						{
							V_9 = V_10.get_Expression() as LiteralExpression;
						}
					}
				}
				else
				{
					V_9 = expression.get_Right() as LiteralExpression;
				}
				if (V_9 != null && V_9.get_Value() == null || V_9.get_Value().Equals(0))
				{
					expression.set_Operator(10);
				}
			}
			if (expression.get_IsObjectComparison())
			{
				V_11 = expression.get_Left();
				V_12 = expression.get_Right();
				if (this.CheckForOverloadedEqualityOperators(expression.get_Left(), out V_13) && this.CheckForOverloadedEqualityOperators(expression.get_Right(), out V_14))
				{
					expression.set_Left(new ExplicitCastExpression(V_11, V_11.get_ExpressionType().get_Module().get_TypeSystem().get_Object(), null, V_13));
					expression.set_Right(new ExplicitCastExpression(V_12, V_12.get_ExpressionType().get_Module().get_TypeSystem().get_Object(), null, V_14));
				}
			}
			return expression;
		}