示例#1
0
        public override BasicValue Merge(BasicValue value1, BasicValue value2)
        {
            if (!value1.Equals(value2))
            {
                var type1 = value1.GetType();
                var type2 = value2.GetType();
                if (type1 != null && (type1.GetSort() == Type.Object || type1.GetSort() == Type.Array
                                      ) && type2 != null && (type2.GetSort() == Type.Object || type2.GetSort() == Type
                                                             .Array))
                {
                    if (type1.Equals(Null_Type))
                    {
                        return(value2);
                    }
                    if (type2.Equals(Null_Type))
                    {
                        return(value1);
                    }
                    if (IsAssignableFrom(type1, type2))
                    {
                        return(value1);
                    }
                    if (IsAssignableFrom(type2, type1))
                    {
                        return(value2);
                    }
                    var numDimensions = 0;
                    if (type1.GetSort() == Type.Array && type2.GetSort() == Type.Array && type1.GetDimensions
                            () == type2.GetDimensions() && type1.GetElementType().GetSort() == Type.Object &&
                        type2.GetElementType().GetSort() == Type.Object)
                    {
                        numDimensions = type1.GetDimensions();
                        type1         = type1.GetElementType();
                        type2         = type2.GetElementType();
                    }

                    while (true)
                    {
                        if (type1 == null || IsInterface(type1))
                        {
                            return(NewArrayValue(Type.GetObjectType("java/lang/Object"), numDimensions));
                        }
                        type1 = GetSuperClass(type1);
                        if (IsAssignableFrom(type1, type2))
                        {
                            return(NewArrayValue(type1, numDimensions));
                        }
                    }
                }

                return(BasicValue.Uninitialized_Value);
            }

            return(value1);
        }
示例#2
0
        protected internal override bool IsSubTypeOf(BasicValue value, BasicValue expected
                                                     )
        {
            var expectedType = expected.GetType();
            var type         = value.GetType();

            switch (expectedType.GetSort())
            {
            case Type.Int:
            case Type.Float:
            case Type.Long:
            case Type.Double:
            {
                return(type.Equals(expectedType));
            }

            case Type.Array:
            case Type.Object:
            {
                if (type.Equals(Null_Type))
                {
                    return(true);
                }

                if (type.GetSort() == Type.Object || type.GetSort() == Type.Array)
                {
                    if (IsAssignableFrom(expectedType, type))
                    {
                        return(true);
                    }
                    if (GetClass(expectedType).IsInterface)
                    {
                        // The merge of class or interface types can only yield class types (because it is not
                        // possible in general to find an unambiguous common super interface, due to multiple
                        // inheritance). Because of this limitation, we need to relax the subtyping check here
                        // if 'value' is an interface.
                        return(Runtime.IsAssignableFrom(typeof(object), GetClass(type)));
                    }
                    return(false);
                }

                return(false);
            }

            default:
            {
                throw new AssertionError();
            }
            }
        }
示例#3
0
        /// <exception cref="AnalyzerException" />
        protected internal override BasicValue GetElementValue(BasicValue objectArrayValue
                                                               )
        {
            var arrayType = objectArrayValue.GetType();

            if (arrayType != null)
            {
                if (arrayType.GetSort() == Type.Array)
                {
                    return(NewValue(Type.GetType(Runtime.Substring(arrayType.GetDescriptor(),
                                                                   1))));
                }
                if (arrayType.Equals(Null_Type))
                {
                    return(objectArrayValue);
                }
            }

            throw new AssertionError();
        }
示例#4
0
        protected internal override bool IsArrayValue(BasicValue value)
        {
            var type = value.GetType();

            return(type != null && (type.GetSort() == Type.Array || type.Equals(Null_Type)));
        }