コード例 #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));
            }
        }
コード例 #2
0
ファイル: any.cs プロジェクト: varivera/EiffelStudio
        public static string generating_type(object Current)
        // Name of Current object's generating type
        // (type of which it is a direct instance)
        {
            string           Result = null;
            RT_CLASS_TYPE    l_type;
            EIFFEL_TYPE_INFO l_current = Current as EIFFEL_TYPE_INFO;

            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else if (l_current != null)
            {
                l_type = l_current.____type();
                if (l_type == null)
                {
                    // Not a generic class.
                    l_type = new RT_CLASS_TYPE(Type.GetTypeHandle(Current));
                }
                Result = l_type.type_name();
            }
            else
            {
                Result = Current.GetType().FullName;
            }
            return(Result);
        }
コード例 #3
0
        public static RT_TYPE load_type_of_object(object an_obj)
        // Given an Eiffel object `an_obj' extract its type information.
        {
            RT_GENERIC_TYPE  l_gen_type;
            RT_CLASS_TYPE    Result;
            EIFFEL_TYPE_INFO l_obj = an_obj as EIFFEL_TYPE_INFO;

            if (l_obj != null)
            {
                l_gen_type = l_obj.____type();
            }
            else
            {
                l_gen_type = null;
            }

            if (l_gen_type == null)
            {
                // It is not an Eiffel generic type or it is a .NET type, so we can simply
                // find its type through Reflection and then creates a RT_CLASS_TYPE object.
                // Note that .NET generic types are treated as non-generic.
                Result = new RT_CLASS_TYPE();
                Result.set_type(an_obj.GetType().TypeHandle);
            }
            else
            {
                // It is a generic type, so we can simply find its type through
                // its RT_GENERIC_TYPE.
                Result = l_gen_type;
            }
            return(Result);
        }
コード例 #4
0
 public static EIFFEL_TYPE_INFO create_like_object(EIFFEL_TYPE_INFO an_obj)
 // Given an Eiffel object `an_obj' create a new one of same type.
 {
     // Create a new instance of the same type of `an_obj'
     // If it is a generic type, we also need to set its type.
     return((EIFFEL_TYPE_INFO)create_instance
                (an_obj.GetType(), an_obj.____type()));
 }
コード例 #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
/*
 * feature -- Status report
 */
        public static int generic_parameter_count(object o)
        // Number of generic Parameter if any.
        {
            int Result = 0;
            EIFFEL_TYPE_INFO l_object = o as EIFFEL_TYPE_INFO;

            if (l_object != null)
            {
                Result = l_object.____type().count;
            }
            return(Result);
        }
コード例 #7
0
        public static RT_CLASS_TYPE type_of_generic(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;

            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));
                ASSERTIONS.REQUIRE("valid element type", l_object.____type().generics [pos - 1] is RT_CLASS_TYPE);
                        #endif

                return((RT_CLASS_TYPE)(l_object.____type().generics [pos - 1]));
            }
            else
            {
                return(null);
            }
        }
コード例 #8
0
        // Mapping between implementation types and interface types.

        public static RT_GENERIC_TYPE generic_type(object an_obj)
        // Given an Eiffel object `an_obj' retrieves its associated type if any.
        {
            EIFFEL_TYPE_INFO l_object = an_obj as EIFFEL_TYPE_INFO;

            if (l_object != null)
            {
                return(l_object.____type());
            }
            else
            {
                return(null);
            }
        }
コード例 #9
0
        public static EIFFEL_TYPE_INFO create_type(
            RT_TYPE a_type,
            EIFFEL_TYPE_INFO a_current
            )
        // Create new instance of `a_type' in context of `a_current' object.
        // Handles creation of class type as well as creation of formal generic parameter.
        {
            RT_CLASS_TYPE   type_to_create;
            RT_GENERIC_TYPE computed_type;

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

            // Create new object of type `type_to_create'.
            computed_type = type_to_create as RT_GENERIC_TYPE;
            return((EIFFEL_TYPE_INFO)create_instance(Type.GetTypeFromHandle(type_to_create.type), computed_type));
        }
コード例 #10
0
        public static Boolean is_eiffel_array(object o)
        // Is `o' an instance of an Eiffel ARRAY.
        {
            RT_GENERIC_TYPE  l_gen_type;
            EIFFEL_TYPE_INFO info   = o as EIFFEL_TYPE_INFO;
            Boolean          Result = false;

            if (info != null)
            {
                l_gen_type = info.____type();
                if (l_gen_type != null)
                {
                    // A generic class, possibly a good candidate for ARRAY.
                    Result = l_gen_type.class_name().Equals("ARRAY");
                }
            }
            return(Result);
        }
コード例 #11
0
        public static Boolean is_eiffel_string(object o)
        // Is `o' an instance of an Eiffel STRING.
        {
            RT_GENERIC_TYPE  l_gen_type;
            EIFFEL_TYPE_INFO info   = o as EIFFEL_TYPE_INFO;
            Boolean          Result = false;

            if (info != null)
            {
                l_gen_type = info.____type();
                if (l_gen_type == null)
                {
                    // Not a generic class, possibly a good candidate for STRING.
                    Result = info.____class_name().Equals("STRING");
                }
            }
            return(Result);
        }
コード例 #12
0
ファイル: gen_conf.cs プロジェクト: tioui/EiffelStudio
        // 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.
        public static object create_array(
		int n,
		RT_TYPE a_type,
		EIFFEL_TYPE_INFO a_current,
		RuntimeTypeHandle any_type_handle
	)
        {
            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);
            }
        }
コード例 #13
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);
        }
コード例 #14
0
ファイル: gen_conf.cs プロジェクト: tioui/EiffelStudio
 // Given an Eiffel object `an_obj' create a new one of same type.
 public static EIFFEL_TYPE_INFO create_like_object(EIFFEL_TYPE_INFO an_obj)
 {
     // Create a new instance of the same type of `an_obj'
     // If it is a generic type, we also need to set its type.
     return (EIFFEL_TYPE_INFO) create_instance
     (an_obj.GetType (), an_obj.____type ());
 }
コード例 #15
0
ファイル: gen_conf.cs プロジェクト: tioui/EiffelStudio
        // Create new instance of `a_type' in context of `a_current' object.
        // Handles creation of class type as well as creation of formal generic parameter.
        public static EIFFEL_TYPE_INFO create_type(
		RT_TYPE a_type,
		EIFFEL_TYPE_INFO a_current
	)
        {
            RT_CLASS_TYPE type_to_create;
            RT_GENERIC_TYPE computed_type;

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

            // Create new object of type `type_to_create'.
            computed_type = type_to_create as RT_GENERIC_TYPE;
            return (EIFFEL_TYPE_INFO) create_instance (Type.GetTypeFromHandle (type_to_create.type), computed_type);
        }