// 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 ()); }
public static void copy(object Current, object other) // Update current object using fields of object attached // to `other', so as to yield equal objects. { EIFFEL_TYPE_INFO l_current = Current as EIFFEL_TYPE_INFO; #if ASSERTIONS ASSERTIONS.REQUIRE("other_not_void", other != null); ASSERTIONS.REQUIRE("same_type", same_type(Current, other)); #endif if (Current == null) { generate_call_on_void_target_exception(); } else { if (l_current != null) { l_current.____copy(other); } else { internal_standard_copy(Current, other); } } #if ASSERTIONS ASSERTIONS.ENSURE("is_equal", is_equal(Current, other)); #endif }
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); }
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); }
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)); } }
/* * feature -- Comparison */ public static bool is_equal(object Current, object other) // Is `other' attached to an object considered // equal to current object? { bool Result = false; EIFFEL_TYPE_INFO l_current = Current 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 (l_current != null) { Result = l_current.____is_equal(other); } else { Result = Current.Equals(other); } return(Result); }
private static void sub_internal_native_array_deep_twin( Array target_array, int i, EIFFEL_TYPE_INFO source_attribute, Hashtable traversed_objects ) // Helper feature that given a `target' object and its associated `attribute' // perform a deep copy of `source_attribute' and assign it back to `target'. // Assume arguments are not Void. { EIFFEL_TYPE_INFO target_attribute; if (traversed_objects.Contains(source_attribute)) { // We already processed `obj', we simply assign current // attribute to computed value. target_array.SetValue(traversed_objects [source_attribute], i); } else { // Ojbect was not yet duplicated. target_attribute = GENERIC_CONFORMANCE.create_like_object(source_attribute); traversed_objects.Add(source_attribute, target_attribute); internal_deep_twin(target_attribute, source_attribute, traversed_objects); target_array.SetValue(target_attribute, i); } }
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())); }
/* * 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); }
// 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); } }
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)); }
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); }
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); }
//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); }
// 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); } }
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); } }
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); }
/* * feature -- Access */ public static string generator(object Current) // Name of Current object's generating class // (base class of the type of which it is a direct instance) { string Result = null; EIFFEL_TYPE_INFO l_current = Current as EIFFEL_TYPE_INFO; if (Current == null) { generate_call_on_void_target_exception(); } else if (l_current != null) { // This is a generated Eiffel type, we extract // stored type. Result = l_current.____class_name(); } else { Result = Current.GetType().Name; } return(Result); }
// Helper feature that given a `target' object and its associated `attribute' // perform a deep copy of `source_attribute' and assign it back to `target'. // Assume arguments are not Void. private static void sub_internal_native_array_deep_twin( Array target_array, int i, EIFFEL_TYPE_INFO source_attribute, Hashtable traversed_objects ) { EIFFEL_TYPE_INFO target_attribute; if (traversed_objects.Contains (source_attribute)) { // We already processed `obj', we simply assign current // attribute to computed value. target_array.SetValue (traversed_objects [source_attribute], i); } else { // Ojbect was not yet duplicated. target_attribute = GENERIC_CONFORMANCE.create_like_object (source_attribute); traversed_objects.Add (source_attribute, target_attribute); internal_deep_twin (target_attribute, source_attribute, traversed_objects); target_array.SetValue (target_attribute, i); } }
// 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); }
/* * 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); }