ilcclib.Converter.CIL.CILConverter.DoBinaryOperation C# (CSharp) Method

DoBinaryOperation() private method

private DoBinaryOperation ( string Operator, CParser Left, CParser Right ) : void
Operator string
Left CParser
Right CParser
return void
        private void DoBinaryOperation(string Operator, CParser.Expression Left, CParser.Expression Right)
        {
            bool EmitConstantValue = true;

            DoGenerateAddress(false, () =>
            {
                var LeftConstant = Left.GetCachedConstantValue(null);
                var RightConstant = Right.GetCachedConstantValue(null);

                // Optimization.
                if ((LeftConstant != null) && (RightConstant != null))
                {
                    //Console.WriteLine("{0} {1} {2}", LeftConstant, Operator, RightConstant);
                    if (LeftConstant.GetType() == typeof(int) && RightConstant.GetType() == typeof(int))
                    {
                        int LeftConstantValue = (int)LeftConstant;
                        int RightConstantValue = (int)RightConstant;
                        switch (Operator)
                        {
                            case "+": SafeILGenerator.Push(LeftConstantValue + RightConstantValue); return;
                            case "-": SafeILGenerator.Push(LeftConstantValue - RightConstantValue); return;
                            case "*": SafeILGenerator.Push(LeftConstantValue * RightConstantValue); return;
                            case "/": SafeILGenerator.Push(LeftConstantValue / RightConstantValue); return;
                            default:
                                Console.Error.WriteLine("Unoptimized binary operator {0}", Operator);
                                break;
                        }
                    }
                }

                Traverse(Left);
                _DoBinaryLeftRightPost(Operator);
                Traverse(Right);
                _DoBinaryLeftRightPost(Operator);
                EmitConstantValue = false;
            });

            if (!EmitConstantValue)
            {
                var LeftCType = Left.GetCachedCType(this).GetCSimpleType();
                var RightCType = Right.GetCachedCType(this).GetCSimpleType();
                _DoBinaryOperation(Operator, LeftCType.Sign);
            }
        }