コード例 #1
0
ファイル: agent_proxy.cs プロジェクト: varivera/EiffelStudio
/*
 * feature -- Basic operations
 */
        public virtual void call(object agent, object[] open_operands)
        // Call associated routine `agent' with open arguments `open_operands'.
        {
                #if ASSERTIONS
            ASSERTIONS.CHECK("open_operands_not_void", open_operands != null);
                #endif
        }
コード例 #2
0
ファイル: agent_proxy.cs プロジェクト: varivera/EiffelStudio
        // Last result of a function call

        public object item(object agent, object[] open_operands)
        // Call associated routine `agent' with open arguments `open_operands'.
        {
                #if ASSERTIONS
            ASSERTIONS.CHECK("open_operands_not_void", open_operands != null);
                #endif
            call(agent, open_operands);
            return(last_result);
        }
コード例 #3
0
        public static bool is_assertion_checked(Type t, ASSERTION_LEVEL_ENUM val, bool saved_caller_supplier_precondition)
        // Are assertions checked for type `t' for assertion type `val'.
        // Note that `val' is not a combination.
        {
            ASSERTION_LEVEL_ENUM type_assertion_level;
            object obj;
            bool   Result;

                #if ASSERTIONS
            ASSERTIONS.CHECK("Valid val",
                             (val == ASSERTION_LEVEL_ENUM.no) ||
                             (val == ASSERTION_LEVEL_ENUM.check) ||
                             (val == ASSERTION_LEVEL_ENUM.require) ||
                             (val == ASSERTION_LEVEL_ENUM.ensure) ||
                             (val == ASSERTION_LEVEL_ENUM.loop) ||
                             (val == ASSERTION_LEVEL_ENUM.invariant));
                #endif

            Result = !in_assertion();
            if (Result)
            {
                if (val == ASSERTION_LEVEL_ENUM.require && saved_caller_supplier_precondition)
                {
                    Result = true;
                }
                else
                {
                    // Let's extract the specified assertion level for type `t'.
                    // If `is_global_assertion_level_set' is set, then we can return
                    // the global one.
                    if (is_global_assertion_level_set)
                    {
                        return((global_assertion_level & val) == val);
                    }
                    else if ((assertion_levels != null))
                    {
                        obj = assertion_levels [t];
                        if (obj != null)
                        {
                            type_assertion_level = (ASSERTION_LEVEL_ENUM)obj;
                        }
                        else
                        {
                            type_assertion_level = ASSERTION_LEVEL_ENUM.no;
                        }
                    }
                    else
                    {
                        type_assertion_level = ASSERTION_LEVEL_ENUM.no;
                    }
                    Result = ((type_assertion_level & val) == val);
                }
            }
            return(Result);
        }
コード例 #4
0
ファイル: any.cs プロジェクト: varivera/EiffelStudio
        public static bool same_type(object Current, object other)
        // Is type of current object identical to type of `other'?
        {
            bool             Result = false;
            RT_GENERIC_TYPE  l_current_type, l_other_type;
            EIFFEL_TYPE_INFO l_current;

                #if ASSERTIONS
            ASSERTIONS.REQUIRE("other_not_void", other != null);
                #endif
            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else
            {
                Result = Current.GetType().Equals(other.GetType());
                if (Result)
                {
                    l_current = Current as EIFFEL_TYPE_INFO;
                    if (l_current != null)
                    {
                        // We perform generic conformance in case it is needed.
                        l_current_type = l_current.____type();
                        if (l_current_type != null)
                        {
                            // Because we already know that `Current' and `other' have
                            // the same type, therefore cast to EIFFEL_TYPE_INFO is
                            // going to succeed.
                            l_other_type = ((EIFFEL_TYPE_INFO)other).____type();
                                                #if ASSERTIONS
                            ASSERTIONS.CHECK("has_derivation", l_other_type != null);
                            ASSERTIONS.CHECK("Same base type", l_current_type.type.Equals(l_other_type.type));
                                                #endif
                            Result = l_current_type.Equals(l_other_type);
                        }
                    }
                    else
                    {
                        // It is not generic, then they definitely have the same type.
                        // No need to assign Result again, as it is already holding the true value.
                    }
                }
            }
#if ASSERTIONS
            ASSERTIONS.ENSURE("definition", Result == (conforms_to(Current, other) &&
                                                       conforms_to(other, Current)));
#endif
            return(Result);
        }
コード例 #5
0
//FIXME: to remove when TUPLE is updated not to use this routine anymore.
        public static Type type_of_generic_parameter(object an_obj, int pos)
        // Given an Eiffel object `an_obj', find the associated type of generic parameter
        // at position `pos'.
        {
            EIFFEL_TYPE_INFO l_object = an_obj as EIFFEL_TYPE_INFO;
            RT_GENERIC_TYPE  l_gen_type;
            RT_CLASS_TYPE    cl_type;
            Type             Result = null;

            if (l_object != null)
            {
                        #if ASSERTIONS
                ASSERTIONS.REQUIRE("Has  generic info", l_object.____type() != null);
                ASSERTIONS.REQUIRE("Valid position `pos'",
                                   (pos > 0) && (pos <= l_object.____type().count));
                        #endif

                l_gen_type = l_object.____type();
                cl_type    = (RT_CLASS_TYPE)l_gen_type.generics [pos - 1];
                if (!cl_type.is_basic())
                {
                    if (cl_type.type.Value != (System.IntPtr) 0)
                    {
                        Result = interface_type(Type.GetTypeFromHandle(cl_type.type));
                    }
                    else
                    {
                        /* Generic parameter is of type NONE, so we return an instance
                         * of RT_NONE_TYPE as associated type. It is mostly there to fix
                         * assertions violations in TUPLE when one of the elements of
                         * a manifest tuple is `Void'. */
                                        #if ASSERTIONS
                        ASSERTIONS.CHECK("Is NONE type.", cl_type is RT_NONE_TYPE);
                                        #endif
                        Result = typeof(RT_NONE_TYPE);
                    }
                }
                else
                {
                    Result = Type.GetTypeFromHandle(cl_type.type);
                }
            }
            return(Result);
        }
コード例 #6
0
ファイル: any.cs プロジェクト: varivera/EiffelStudio
/*
 * 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);
        }
コード例 #7
0
        // Tag of last checked assertion

        public static void assertion_initialize(RuntimeTypeHandle type_handle)
        // Initializes runtime datastructure for assembly associated with
        // `type_handle'.
        {
            assertion_levels = new Hashtable(100);
            Assembly a = Type.GetTypeFromHandle(type_handle).Assembly;
            ASSERTION_LEVEL_ATTRIBUTE level_attribute;
            ASSERTION_LEVEL_ENUM      l_common_level, l_current_level;
            bool l_computed, l_same_level;

                #if ASSERTIONS
            ASSERTIONS.CHECK("There should be an assembly", a != null);
                #endif

            try {
                object [] cas = a.GetCustomAttributes(typeof(ASSERTION_LEVEL_ATTRIBUTE), false);
                if ((cas != null) && (cas.Length > 0))
                {
                    l_same_level   = true;
                    l_computed     = false;
                    l_common_level = ASSERTION_LEVEL_ENUM.no;
                    foreach (object ca in cas)
                    {
                        level_attribute = (ASSERTION_LEVEL_ATTRIBUTE)ca;
                        l_current_level = level_attribute.assertion_level;
                        assertion_levels.Add(
                            level_attribute.class_type,                 // key
                            l_current_level);                           // value
                        if (!l_computed)
                        {
                            l_common_level = l_current_level;
                            l_computed     = true;
                        }
                        else
                        {
                            if (l_same_level)
                            {
                                l_same_level = (l_common_level == l_current_level);
                            }
                        }
                    }
                    if (l_same_level)
                    {
                        global_assertion_level        = l_common_level;
                        is_global_assertion_level_set = true;
                    }
                    else
                    {
                        is_global_assertion_level_set = false;
                    }
                }
                else
                {
                    global_assertion_level        = ASSERTION_LEVEL_ENUM.no;
                    is_global_assertion_level_set = true;
                }
            } catch {
                global_assertion_level        = ASSERTION_LEVEL_ENUM.no;
                is_global_assertion_level_set = true;
            }
        }