private ITypeRef ArithmeticType(IComparisonOperand operand)
 {
     if (operand is ConstValue)
     {
         return(PrimitiveType(((ConstValue)operand).Value().GetType()));
     }
     if (operand is FieldValue)
     {
         return(((FieldValue)operand).Field.Type);
     }
     if (operand is ArithmeticExpression)
     {
         ArithmeticExpression expr  = (ArithmeticExpression)operand;
         ITypeRef             left  = ArithmeticType(expr.Left());
         ITypeRef             right = ArithmeticType(expr.Right());
         if (left == DoubleType() || right == DoubleType())
         {
             return(DoubleType());
         }
         if (left == FloatType() || right == FloatType())
         {
             return(FloatType());
         }
         if (left == LongType() || right == LongType())
         {
             return(LongType());
         }
         return(IntType());
     }
     return(null);
 }
Example #2
0
        public void Visit(ArithmeticExpression operand)
        {
            operand.Left().Accept(this);
            object left = _value;

            operand.Right().Accept(this);
            object right = _value;

            switch (operand.Op().Id())
            {
            case ArithmeticOperator.AddId:
            {
                _value = Add(left, right);
                break;
            }

            case ArithmeticOperator.SubtractId:
            {
                _value = Subtract(left, right);
                break;
            }

            case ArithmeticOperator.MultiplyId:
            {
                _value = Multiply(left, right);
                break;
            }

            case ArithmeticOperator.DivideId:
            {
                _value = Divide(left, right);
                break;
            }
            }
        }
        public virtual void Visit(ArithmeticExpression operand)
        {
            bool oldInArithmetic = _inArithmetic;

            _inArithmetic = true;
            operand.Left().Accept(this);
            operand.Right().Accept(this);
            ITypeRef operandType = ArithmeticType(operand);

            switch (operand.Op().Id())
            {
            case ArithmeticOperator.AddId:
            {
                _methodBuilder.Add(operandType);
                break;
            }

            case ArithmeticOperator.SubtractId:
            {
                _methodBuilder.Subtract(operandType);
                break;
            }

            case ArithmeticOperator.MultiplyId:
            {
                _methodBuilder.Multiply(operandType);
                break;
            }

            case ArithmeticOperator.DivideId:
            {
                _methodBuilder.Divide(operandType);
                break;
            }

            case ArithmeticOperator.ModuloId:
            {
                _methodBuilder.Modulo(operandType);
                break;
            }

            default:
            {
                throw new Exception("Unknown operand: " + operand.Op());
            }
            }
            Box(_opClass, !oldInArithmetic);
            _inArithmetic = oldInArithmetic;
        }
Example #4
0
 public virtual void Visit(ArithmeticExpression operand)
 {
     operand.Left().Accept(this);
     operand.Right().Accept(this);
 }