示例#1
0
        /// <summary>
        /// Evalaute this node and return result.
        /// </summary>
        /// <param name="thisObject">Reference to object that is exposed as 'this'.</param>
        /// <returns>Result value and type of that result.</returns>
        public override EvalResult Evaluate(object thisObject)
        {
            // Get the result from evaluating both children
            EvalResult left  = this[0].Evaluate(thisObject);
            EvalResult right = this[1].Evaluate(thisObject);

            int count;

            if (_language == Language.CSharp)
            {
                // The shift count is always an Int32, so convert anything smaller to an Int32
                switch (right.Type)
                {
                case TypeCode.Char:
                    count = (Int32)(Char)right.Value;
                    break;

                case TypeCode.Byte:
                    count = (Int32)(Byte)right.Value;
                    break;

                case TypeCode.SByte:
                    count = (Int32)(SByte)right.Value;
                    break;

                case TypeCode.UInt16:
                    count = (Int32)(UInt16)right.Value;
                    break;

                case TypeCode.Int16:
                    count = (Int32)(Int16)right.Value;
                    break;

                case TypeCode.Int32:
                    count = (Int32)right.Value;
                    break;

                default:
                    throw new ApplicationException("Shift operation '" + OperationString + "' cannot convert the shift count from type '" + right.Type.ToString() + "' to 'Int32'.");
                }
            }
            else
            {
                if (ImplicitConverter.CanConvertToInt32(right.Value, Language.VBNet))
                {
                    count = ImplicitConverter.ConvertToInt32(right.Value, Language.VBNet);
                }
                else
                {
                    throw new ApplicationException("Shift operation '" + OperationString + "' cannot convert the shift count to a 'Int32' value.");
                }
            }

            // Perform the actual shift operation
            switch (left.Type)
            {
            case TypeCode.Byte:
                return(EvalShiftOp((Int32)(Byte)left.Value, count));

            case TypeCode.SByte:
                return(EvalShiftOp((Int32)(SByte)left.Value, count));

            case TypeCode.Char:
                if (_language == Language.CSharp)
                {
                    return(EvalShiftOp((Int32)(Char)left.Value, count));
                }
                break;

            case TypeCode.UInt16:
                return(EvalShiftOp((Int32)(UInt16)left.Value, count));

            case TypeCode.Int16:
                return(EvalShiftOp((Int32)(Int16)left.Value, count));

            case TypeCode.Int32:
                return(EvalShiftOp((Int32)(Int32)left.Value, count));

            case TypeCode.UInt32:
                return(EvalShiftOp((UInt32)left.Value, count));

            case TypeCode.Int64:
                return(EvalShiftOp((Int64)left.Value, count));

            case TypeCode.UInt64:
                return(EvalShiftOp((UInt64)left.Value, count));

            case TypeCode.Boolean:
                if (_language == Language.VBNet)
                {
                    return(EvalShiftOp((Int16)ImplicitConverter.ConvertToInt16(left.Value, Language.VBNet), count));
                }
                break;

            case TypeCode.Single:
                if (_language == Language.VBNet)
                {
                    return(EvalShiftOp((Int64)(Single)left.Value, count));
                }
                break;

            case TypeCode.Double:
                if (_language == Language.VBNet)
                {
                    return(EvalShiftOp((Int64)(Double)left.Value, count));
                }
                break;

            case TypeCode.Decimal:
                if (_language == Language.VBNet)
                {
                    return(EvalShiftOp((Int64)(Decimal)left.Value, count));
                }
                break;
            }

            throw new ApplicationException("Shift operation '" + OperationString + "' cannot shift type '" + left.Type.ToString() + "'.");
        }