Exemplo n.º 1
0
        public override ITypedValue GetValueInternal(ExpressionState state)
        {
            if (_name.Equals(_THIS))
            {
                return(state.GetActiveContextObject());
            }

            if (_name.Equals(_ROOT))
            {
                var obj = state.RootContextObject;
                _exitTypeDescriptor = CodeFlow.ToDescriptorFromObject(obj.Value);
                return(obj);
            }

            var result = state.LookupVariable(_name);
            var value  = result.Value;

            if (value == null || !value.GetType().IsPublic)
            {
                // If the type is not public then when generateCode produces a checkcast to it
                // then an IllegalAccessError will occur.
                // If resorting to Object isn't sufficient, the hierarchy could be traversed for
                // the first public type.
                _exitTypeDescriptor = "Ljava/lang/Object";
            }
            else
            {
                _exitTypeDescriptor = CodeFlow.ToDescriptorFromObject(value);
            }

            // a null value will mean either the value was null or the variable was not found
            return(result);
        }
Exemplo n.º 2
0
        public override ITypedValue GetValueInternal(ExpressionState state)
        {
            var leftValue  = LeftOperand.GetValueInternal(state).Value;
            var rightValue = RightOperand.GetValueInternal(state).Value;

            _leftActualDescriptor  = CodeFlow.ToDescriptorFromObject(leftValue);
            _rightActualDescriptor = CodeFlow.ToDescriptorFromObject(rightValue);
            return(BooleanTypedValue.ForValue(!EqualityCheck(state.EvaluationContext, leftValue, rightValue)));
        }
Exemplo n.º 3
0
        protected internal TypeDescriptor ComputeExitDescriptor(object result, Type propertyReturnType)
        {
            if (propertyReturnType.IsValueType)
            {
                return(CodeFlow.ToDescriptor(propertyReturnType));
            }

            return(CodeFlow.ToDescriptorFromObject(result));
        }
Exemplo n.º 4
0
        public override ITypedValue GetValueInternal(ExpressionState state)
        {
            var left  = LeftOperand.GetValueInternal(state).Value;
            var right = RightOperand.GetValueInternal(state).Value;

            _leftActualDescriptor  = CodeFlow.ToDescriptorFromObject(left);
            _rightActualDescriptor = CodeFlow.ToDescriptorFromObject(right);

            if (IsNumber(left) && IsNumber(right))
            {
                var leftConv  = (IConvertible)left;
                var rightConv = (IConvertible)right;

                if (left is decimal || right is decimal)
                {
                    var leftVal  = leftConv.ToDecimal(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToDecimal(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal.CompareTo(rightVal) <= 0));
                }
                else if (left is double || right is double)
                {
                    var leftVal  = leftConv.ToDouble(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToDouble(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
                else if (left is float || right is float)
                {
                    var leftVal  = leftConv.ToSingle(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToSingle(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
                else if (left is long || right is long)
                {
                    var leftVal  = leftConv.ToInt64(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToInt64(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
                else if (left is int || right is int)
                {
                    var leftVal  = leftConv.ToInt32(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToInt32(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
                else if (left is short || right is short)
                {
                    var leftVal  = leftConv.ToInt16(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToInt16(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
                else if (left is byte || right is byte)
                {
                    var leftVal  = leftConv.ToByte(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToByte(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
                else if (left is ulong || right is ulong)
                {
                    var leftVal  = leftConv.ToUInt64(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToUInt64(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
                else if (left is uint || right is uint)
                {
                    var leftVal  = leftConv.ToUInt32(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToUInt32(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
                else if (left is ushort || right is ushort)
                {
                    var leftVal  = leftConv.ToUInt16(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToUInt16(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
                else if (left is sbyte || right is sbyte)
                {
                    var leftVal  = leftConv.ToSByte(CultureInfo.InvariantCulture);
                    var rightVal = rightConv.ToSByte(CultureInfo.InvariantCulture);
                    return(BooleanTypedValue.ForValue(leftVal <= rightVal));
                }
            }

            return(BooleanTypedValue.ForValue(state.TypeComparator.Compare(left, right) <= 0));
        }