コード例 #1
0
        /// <summary>
        /// Convert StackValue to boolean typed StackValue. Returns
        /// StackValue.Null if not able to do conversion.
        /// </summary>
        /// <param name="core"></param>
        /// <returns></returns>
        public StackValue ToBoolean(Core core)
        {
            switch (optype)
            {
            case AddressType.Boolean:
                return(this);

            case AddressType.Int:
                return(BuildBoolean(opdata != 0));

            case AddressType.Null:
                return(StackValue.Null);

            case AddressType.Double:
                bool b = !Double.IsNaN(RawDoubleValue) && !RawDoubleValue.Equals(0.0);
                return(BuildBoolean(b));

            case AddressType.Pointer:
                return(StackValue.BuildBoolean(true));

            case AddressType.String:
                string str = core.Heap.GetString(this);
                return(string.IsNullOrEmpty(str) ? StackValue.False : StackValue.True);

            case AddressType.Char:
                char c = EncodingUtils.ConvertInt64ToCharacter(opdata);
                return((c == 0) ? StackValue.False : StackValue.True);

            default:
                return(StackValue.Null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Convert StackValue to boolean typed StackValue. Returns
        /// StackValue.Null if not able to do conversion.
        /// </summary>
        /// <param name="core"></param>
        /// <returns></returns>
        public StackValue ToBoolean(RuntimeCore runtimeCore)
        {
            switch (optype)
            {
            case AddressType.Boolean:
                return(this);

            case AddressType.Int:
                return(BuildBoolean(opdata != 0));

            case AddressType.Null:
                return(StackValue.Null);

            case AddressType.Double:
                bool b = !Double.IsNaN(RawDoubleValue) && !RawDoubleValue.Equals(0.0);
                return(BuildBoolean(b));

            case AddressType.Pointer:
                return(StackValue.BuildBoolean(true));

            case AddressType.String:
                string str = runtimeCore.RuntimeMemory.Heap.ToHeapObject <DSString>(this).Value;
                return(string.IsNullOrEmpty(str) ? StackValue.False : StackValue.True);

            case AddressType.Char:
                char c = Convert.ToChar(opdata);
                return((c == 0) ? StackValue.False : StackValue.True);

            default:
                return(StackValue.Null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Convert StackValue to boolean typed StackValue. Returns
        /// StackValue.Null if not able to do conversion.
        /// </summary>
        /// <param name="core"></param>
        /// <returns></returns>
        public StackValue ToBoolean(Core core)
        {
            switch (optype)
            {
            case AddressType.Boolean:
                return(this);

            case AddressType.Int:
                return(BuildBoolean(opdata != 0));

            case AddressType.Null:
                return(StackValue.Null);

            case AddressType.Double:
                bool b = !Double.IsNaN(RawDoubleValue) && !RawDoubleValue.Equals(0.0);
                return(BuildBoolean(b));

            case AddressType.Pointer:
                return(StackValue.BuildBoolean(true));

            case AddressType.String:
                int size = ArrayUtils.GetElementSize(this, core);
                return((size == 0) ? StackValue.False : StackValue.True);

            case AddressType.Char:
                char c = EncodingUtils.ConvertInt64ToCharacter(opdata);
                return((c == 0) ? StackValue.False : StackValue.True);

            default:
                return(StackValue.Null);
            }
        }