Пример #1
0
        public virtual bool TryGetConstValueWithCast(CppTypeName cast, out object value)
        {
            if (!TryGetConstValue(out value))
            {
                return(false);
            }
            var type = ProjectConverter.GetConstValueType(value);

            if (type == cast)
            {
                return(true);
            }
            if (P.IsArithmeticType(type) && P.IsArithmeticType(cast))
            {
                var NumberConverter = new Dictionary <CppTypeName, Func <object, object> > {
                    { ProjectConverter.CppTypeName_Byte, x => Convert.ToByte(x) },
                    { ProjectConverter.CppTypeName_Short, x => Convert.ToInt16(x) },
                    { ProjectConverter.CppTypeName_Int, x => Convert.ToInt32(x) },
                    { ProjectConverter.CppTypeName_Long, x => Convert.ToInt64(x) },
                    { ProjectConverter.CppTypeName_Float, x => Convert.ToSingle(x) },
                    { ProjectConverter.CppTypeName_Double, x => Convert.ToDouble(x) },
                };
                if (NumberConverter.TryGetValue(cast, out var converter))
                {
                    value = converter(value);
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
 public override CppTypeName GetResultType()
 {
     if (!TryGetConstValue(out var v))
     {
         throw new Exception();
     }
     return(ProjectConverter.GetConstValueType(v));
 }
Пример #3
0
        public virtual bool TryGetConstValueWithCast(CppTypeName cast, out object value)
        {
            if (!TryGetConstValue(out value))
            {
                return(false);
            }
            var type = ProjectConverter.GetConstValueType(value);

            if (type == cast)
            {
                return(true); //FIXME 类型自动转换
            }
            return(false);
        }