Example #1
0
        public static object create_array(
            int n,
            RT_TYPE a_type,
            EIFFEL_TYPE_INFO a_current,
            RuntimeTypeHandle any_type_handle
            )
        // Create new instance of an array type whose element types are `a_type' in context of
        // `a_current' object.
        // Handles elements that are class types as well as formals.
        {
            RT_CLASS_TYPE type_to_create;

            // Evaluate type in context of Current object.
            type_to_create = (RT_CLASS_TYPE)a_type.evaluated_type(a_current.____type());

            if (type_to_create.is_none() || (type_to_create.type.Value == any_type_handle.Value))
            {
                return(new object [n]);
            }
            else
            {
                return(Array.CreateInstance(
                           ISE_RUNTIME.interface_type(Type.GetTypeFromHandle(type_to_create.type)), n));
            }
        }
Example #2
0
 public static void CHECK(String msg, bool expression)
 // Throw a check violation if `expression' is not true.
 {
     if (!expression)
     {
         ISE_RUNTIME.raise_check(msg);
     }
 }
Example #3
0
 public static void ENSURE(String msg, bool expression)
 // Throw a postcondition violation if `expression' is not true.
 {
     if (!expression)
     {
         ISE_RUNTIME.raise_postcondition(msg);
     }
 }
Example #4
0
/*
 * feature -- Duplication
 */
        public static object twin(object Current)
        // New object equal to `Current'
        // `twin' calls `copy'; to change copying/twining semantics, redefine `copy'.
        {
            object Result = null;
            bool   l_check_assert;

            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else
            {
                l_check_assert = ISE_RUNTIME.check_assert(false);
                Result         = GENERIC_CONFORMANCE.create_like_object(Current);
                copy(Result, Current);
                l_check_assert = ISE_RUNTIME.check_assert(l_check_assert);
            }
            return(Result);
        }
Example #5
0
        public static object standard_twin(object Current)
        // New object field-by-field identical to `other'.
        // Always uses default copying semantics.
        {
            object           Result = null;
            bool             l_check_assert;
            EIFFEL_TYPE_INFO l_current = Current as EIFFEL_TYPE_INFO;

            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else
            {
                if (l_current != null)
                {
                    // For Eiffel object we can use our efficient implementation
                    // which is using `MemberwiseClone'.
                    Result = l_current.____standard_twin();
                }
                else
                {
                    // For .NET object, we have to do it the slow way, allocate
                    // a new object, and then copy field by field.
                    l_check_assert = ISE_RUNTIME.check_assert(false);
                    Result         = GENERIC_CONFORMANCE.create_like_object(Current);
                    internal_standard_copy(Result, Current);
                    l_check_assert = ISE_RUNTIME.check_assert(l_check_assert);
                }
            }

                #if ASSERTIONS
            ASSERTIONS.ENSURE("standard_twin_not_void", Result != null);
            ASSERTIONS.ENSURE("standard_equal", standard_equal(Current, Result, Current));
                #endif

            return(Result);
        }
Example #6
0
/*
 * feature {NONE} -- Implementation
 */
        private static void generate_call_on_void_target_exception()
        // Throw VOID_EXCEPTION
        // when first argument of static routine of ANY is Void.
        {
            ISE_RUNTIME.generate_call_on_void_target_exception();
        }
Example #7
0
/*
 * feature -- Status report
 */

        public static bool conforms_to(object Current, object other)
        // Does type of current object conform to type
        // of `other' (as per Eiffel: The Language, chapter 13)?
        {
            bool             Result = false;
            RT_GENERIC_TYPE  l_current_type, l_other_type;
            EIFFEL_TYPE_INFO current_info = Current as EIFFEL_TYPE_INFO;
            EIFFEL_TYPE_INFO other_info   = other as EIFFEL_TYPE_INFO;

                #if ASSERTIONS
            ASSERTIONS.REQUIRE("other_not_void", other != null);
                #endif
            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else
            {
                if (other_info == null)
                {
                    // `other' is not an Eiffel object, we simply check for .NET conformance
                    Result = other.GetType().IsAssignableFrom(Current.GetType());
                }
                else if (current_info == null)
                {
                    // `other' is an Eiffel object, but not `Current', therefore there is
                    // no conformance. We do nothing since `Result' is already initialized to
                    // false.
                }
                else
                {
                    l_current_type = current_info.____type();
                    l_other_type   = other_info.____type();
                    if (l_other_type == null)
                    {
                        // Parent type represented by the `other' instance
                        // is not generic, therefore `Current' should directly
                        // conform to the parent type.
                        Result = ISE_RUNTIME.interface_type(other_info.GetType()).IsAssignableFrom(Current.GetType());
                    }
                    else if (l_current_type == null)
                    {
                        // Parent is generic, but not type represented by
                        // `Current', so let's first check if it simply
                        // conforms without looking at the generic parameter.
                        Result = ISE_RUNTIME.interface_type(other_info.GetType()).IsAssignableFrom(Current.GetType());
                        if (Result)
                        {
                            // It does conform, so now we have to go through
                            // the parents to make sure it has the same generic
                            // derivation.
                            // FIXME: we should use feature `conform_to' from RT_TYPE here.
                        }
                    }
                    else
                    {
                        // Both types are generic. We first check if they
                        // simply conforms.
                                        #if ASSERTIONS
                        ASSERTIONS.CHECK("l_current_type_not_void", l_current_type != null);
                        ASSERTIONS.CHECK("l_other_type_not_void", l_other_type != null);
                                        #endif
                        Result = ISE_RUNTIME.interface_type(other_info.GetType()).IsAssignableFrom(Current.GetType());
                        if (Result)
                        {
                            Result = l_current_type.conform_to(l_other_type);
                        }
                    }
                }
            }
            return(Result);
        }