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 }
/* * 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); }
public static bool standard_is_equal(object Current, object other) // Is `other' attached to an object of the same type // as current object, and field-by-field identical to it? { bool Result = false; FieldInfo [] l_attributes; object l_attr; #if ASSERTIONS ASSERTIONS.REQUIRE("other_not_void", other != null); #endif if (Current == null) { generate_call_on_void_target_exception(); } else { // Optimization: if objects are the same, then they are equal. Result = (Current == other); if (!Result) { if (same_type(Current, other)) { l_attributes = other.GetType().GetFields( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo attribute in l_attributes) { l_attr = attribute.GetValue(other); if (l_attr is ValueType) { Result = Equals(l_attr, attribute.GetValue(Current)); } else { Result = (l_attr == attribute.GetValue(Current)); if (!Result) { /* Special case here where we check whether or not `l_attr' corresponds * to the special runtime field `$$____type' used to store the generic type * information. If it is the case, we simply ignore it. To identify * it we use the name of the attribute as well as its type which needs * to be of type RT_GENERIC_TYPE. */ Result = (attribute.Name.Equals("$$____type") && typeof(RT_GENERIC_TYPE).Equals(attribute.FieldType)); } } if (!Result) { // Force exit from loop as objects are not identical. return(Result); } } } } } return(Result); }
/* * feature -- Duplication */ public static object standard_clone(object obj) // { #if ASSERTIONS ASSERTIONS.REQUIRE("Valid type", obj is EIFFEL_TYPE_INFO); #endif return(GENERIC_CONFORMANCE.create_like_object((EIFFEL_TYPE_INFO)obj)); }
/* * feature -- Output */ public static string @out(object Current) // New string containing terse printable representation // of current object { #if ASSERTIONS ASSERTIONS.REQUIRE("Not an Eiffel object", !(Current is EIFFEL_TYPE_INFO)); #endif return(tagged_out(Current)); }
public static ulong object_size(object obj) // Physical size of an object. { #if ASSERTIONS ASSERTIONS.REQUIRE("obj not void", obj != null); #endif return((ulong)System.Runtime.InteropServices.Marshal.SizeOf(obj.GetType())); }
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); }
public static string tagged_out(object Current) // New string containing terse printable representation // of current object { #if ASSERTIONS ASSERTIONS.REQUIRE("Not an Eiffel object", !(Current is EIFFEL_TYPE_INFO)); #endif string Result = null; if (Current == null) { generate_call_on_void_target_exception(); } else { Result = Current.ToString(); } 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); }
public static void deep_copy(object Current, object other) // Effect equivalent to that of: // `copy' (`other' . `deep_twin') { #if ASSERTIONS ASSERTIONS.REQUIRE("other_not_void", other != null); #endif if (Current == null) { generate_call_on_void_target_exception(); } else { copy(Current, deep_twin(other)); } #if ASSERTIONS ASSERTIONS.ENSURE("deep_equal", deep_equal(Current, Current, other)); #endif }
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 Type interface_type(Type a_type) // Given a type `a_type' retrieves its associated interface type if any (i.e. only // it is an Eiffel type). // Used for conformance because the .NET routine `GetType()' will always return // the implementation type and it cannot be used for conformance because two implementation // classes do not conform even if their interfaces do. { object [] l_attributes; Type result; #if ASSERTIONS ASSERTIONS.REQUIRE("a_type not null", a_type != null); #endif result = interface_type_mapping [a_type] as Type; if (result == null) { l_attributes = a_type.GetCustomAttributes(typeof(RT_INTERFACE_TYPE_ATTRIBUTE), false); if (l_attributes != null && l_attributes.Length > 0) { result = ((RT_INTERFACE_TYPE_ATTRIBUTE)l_attributes [0]).class_type; } else { l_attributes = a_type.GetCustomAttributes(typeof(INTERFACE_TYPE_ATTRIBUTE), false); if (l_attributes != null && l_attributes.Length > 0) { result = ((INTERFACE_TYPE_ATTRIBUTE)l_attributes [0]).class_type; } else { result = a_type; } } interface_type_mapping [a_type] = result; } return(result); }
/* * 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); }