X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Ftypemanager.cs;h=c65cf80ef1085cfe49123af140b1aefedf947368;hb=cdbe8fc8eef496340466bc5e6e7e0687f5058145;hp=50e504c5165a64fbc9734a5d43e89d1b20f22290;hpb=f73e0d5c67f0d26e85b92fc4b75fc48783f20d64;p=mono.git diff --git a/mcs/mcs/typemanager.cs b/mcs/mcs/typemanager.cs index 50e504c5165..c65cf80ef10 100644 --- a/mcs/mcs/typemanager.cs +++ b/mcs/mcs/typemanager.cs @@ -90,6 +90,8 @@ public class TypeManager { static public Type conditional_attribute_type; static public Type in_attribute_type; static public Type out_attribute_type; + static public Type default_parameter_value_attribute_type; + static public Type anonymous_method_type; static public Type cls_compliant_attribute_type; static public Type typed_reference_type; @@ -114,13 +116,6 @@ public class TypeManager { static internal Type default_charset_type; #endif - // - // An empty array of types - // - static public Type [] NoTypes; - static public TypeExpr [] NoTypeExprs; - - // // Expressions representing the internal types. Used during declaration // definition. @@ -195,7 +190,7 @@ public class TypeManager { // The attribute constructors. // static public ConstructorInfo object_ctor; - static public ConstructorInfo cons_param_array_attribute; + static private ConstructorInfo cons_param_array_attribute; static public ConstructorInfo void_decimal_ctor_five_args; static public ConstructorInfo void_decimal_ctor_int_arg; static public ConstructorInfo unverifiable_code_ctor; @@ -251,7 +246,9 @@ public class TypeManager { public static Hashtable AllClsTopLevelTypes; static Hashtable fieldbuilders_to_fields; + static Hashtable propertybuilder_to_property; static Hashtable fields; + static Hashtable events; struct Signature { public string name; @@ -273,6 +270,7 @@ public class TypeManager { events = null; priv_fields_events = null; type_hash = null; + propertybuilder_to_property = null; TypeHandle.CleanUp (); } @@ -366,12 +364,13 @@ public class TypeManager { indexer_arguments = new PtrHashtable (); builder_to_ifaces = new PtrHashtable (); - NoTypes = new Type [0]; - NoTypeExprs = new TypeExpr [0]; - fieldbuilders_to_fields = new Hashtable (); + propertybuilder_to_property = new Hashtable (); fields = new Hashtable (); type_hash = new DoubleHash (); + + // to uncover regressions + cons_param_array_attribute = null; } public static void AddUserType (DeclSpace ds) @@ -583,9 +582,9 @@ public class TypeManager { { PropertyInfo pi = mi as PropertyInfo; if (pi != null) { - MethodBase pmi = pi.GetGetMethod (); + MethodBase pmi = pi.GetGetMethod (true); if (pmi == null) - pmi = pi.GetSetMethod (); + pmi = pi.GetSetMethod (true); if (GetParameterData (pmi).Count > 0) mi = pmi; } @@ -751,13 +750,16 @@ public class TypeManager { /// /// Returns the ConstructorInfo for "args" /// - public static ConstructorInfo GetConstructor (Type t, Type [] args) + private static ConstructorInfo GetConstructor (Type t, Type [] args) { MemberList list; Signature sig; sig.name = ".ctor"; sig.args = args; + + if (t == null) + throw new InternalErrorException ("Core types haven't been initialized yet?"); list = FindMembers (t, MemberTypes.Constructor, instance_and_static | BindingFlags.Public | BindingFlags.DeclaredOnly, @@ -840,6 +842,9 @@ public class TypeManager { param_array_type = CoreLookupType ("System", "ParamArrayAttribute"); in_attribute_type = CoreLookupType ("System.Runtime.InteropServices", "InAttribute"); out_attribute_type = CoreLookupType ("System.Runtime.InteropServices", "OutAttribute"); +#if NET_2_0 + default_parameter_value_attribute_type = CoreLookupType ("System.Runtime.InteropServices", "DefaultParameterValueAttribute"); +#endif typed_reference_type = CoreLookupType ("System", "TypedReference"); arg_iterator_type = CoreLookupType ("System", "ArgIterator"); mbr_type = CoreLookupType ("System", "MarshalByRefObject"); @@ -888,13 +893,12 @@ public class TypeManager { system_type_type = typeof (System.Type); system_assemblybuilder_type = typeof (System.Reflection.Emit.AssemblyBuilder); - Type [] void_arg = { }; system_int_array_get_length = GetMethod ( - system_array_type, "get_Length", void_arg); + system_array_type, "get_Length", Type.EmptyTypes); system_int_array_get_rank = GetMethod ( - system_array_type, "get_Rank", void_arg); + system_array_type, "get_Rank", Type.EmptyTypes); system_object_array_clone = GetMethod ( - system_array_type, "Clone", void_arg); + system_array_type, "Clone", Type.EmptyTypes); Type [] system_int_arg = { system_int32_type }; system_int_array_get_length_int = GetMethod ( @@ -1021,23 +1025,22 @@ public class TypeManager { // // Void arguments // - Type [] void_arg = { }; ienumerator_getcurrent = GetProperty ( ienumerator_type, "Current"); bool_movenext_void = GetMethod ( - ienumerator_type, "MoveNext", void_arg); + ienumerator_type, "MoveNext", Type.EmptyTypes); void_reset_void = GetMethod ( - ienumerator_type, "Reset", void_arg); + ienumerator_type, "Reset", Type.EmptyTypes); void_dispose_void = GetMethod ( - idisposable_type, "Dispose", void_arg); + idisposable_type, "Dispose", Type.EmptyTypes); int_get_offset_to_string_data = GetMethod ( - runtime_helpers_type, "get_OffsetToStringData", void_arg); + runtime_helpers_type, "get_OffsetToStringData", Type.EmptyTypes); int_array_get_length = GetMethod ( - array_type, "get_Length", void_arg); + array_type, "get_Length", Type.EmptyTypes); int_array_get_rank = GetMethod ( - array_type, "get_Rank", void_arg); + array_type, "get_Rank", Type.EmptyTypes); ienumerable_getenumerator_void = GetMethod ( - ienumerable_type, "GetEnumerator", void_arg); + ienumerable_type, "GetEnumerator", Type.EmptyTypes); // // Int32 arguments @@ -1054,7 +1057,7 @@ public class TypeManager { // System.Array methods // object_array_clone = GetMethod ( - array_type, "Clone", void_arg); + array_type, "Clone", Type.EmptyTypes); Type [] array_int_arg = { array_type, int32_type }; void_array_copyto_array_int = GetMethod ( array_type, "CopyTo", array_int_arg); @@ -1091,8 +1094,7 @@ public class TypeManager { // // Attributes // - cons_param_array_attribute = GetConstructor (param_array_type, void_arg); - unverifiable_code_ctor = GetConstructor (unverifiable_code_type, void_arg); + unverifiable_code_ctor = GetConstructor (unverifiable_code_type, Type.EmptyTypes); default_member_ctor = GetConstructor (default_member_type, string_); Type[] short_arg = { short_type }; @@ -1109,15 +1111,23 @@ public class TypeManager { // #if NET_2_0 compiler_generated_attr = new CustomAttributeBuilder ( - GetConstructor (compiler_generated_attr_type, void_arg), new object[0]); + GetConstructor (compiler_generated_attr_type, Type.EmptyTypes), new object[0]); Type[] type_int_arg = { type_type, int32_type }; fixed_buffer_attr_ctor = GetConstructor (fixed_buffer_attr_type, type_int_arg); #endif // Object - object_ctor = GetConstructor (object_type, void_arg); + object_ctor = GetConstructor (object_type, Type.EmptyTypes); + + } + static public ConstructorInfo ConsParamArrayAttribute { + get { + if (cons_param_array_attribute == null) + cons_param_array_attribute = GetConstructor (param_array_type, Type.EmptyTypes); + return cons_param_array_attribute; + } } const BindingFlags instance_and_static = BindingFlags.Static | BindingFlags.Instance; @@ -1489,12 +1499,10 @@ public class TypeManager { static public void RegisterOverride (MethodBase override_method, MethodBase base_method) { - if (method_overrides.Contains (override_method)) { - if (method_overrides [override_method] != base_method) - throw new InternalErrorException ("Override mismatch: " + override_method); - return; - } - method_overrides [override_method] = base_method; + if (!method_overrides.Contains (override_method)) + method_overrides [override_method] = base_method; + if (method_overrides [override_method] != base_method) + throw new InternalErrorException ("Override mismatch: " + override_method); } static public bool IsOverride (MethodBase m) @@ -1504,6 +1512,11 @@ public class TypeManager { (m is MethodBuilder || method_overrides.Contains (m)); } + static public MethodBase TryGetBaseDefinition (MethodBase m) + { + return (MethodBase) method_overrides [m]; + } + /// /// Returns the argument types for an indexer based on its PropertyInfo /// @@ -1519,12 +1532,12 @@ public class TypeManager { // If we're a PropertyBuilder and not in the // `indexer_arguments' hash, then we're a property and // not an indexer. - return NoTypes; + return Type.EmptyTypes; else { ParameterInfo [] pi = indexer.GetIndexParameters (); // Property, not an indexer. if (pi == null) - return NoTypes; + return Type.EmptyTypes; int c = pi.Length; Type [] types = new Type [c]; @@ -1549,6 +1562,16 @@ public class TypeManager { return (IConstant)fields [fb]; } + public static void RegisterProperty (PropertyInfo pi, PropertyBase pb) + { + propertybuilder_to_property.Add (pi, pb); + } + + public static PropertyBase GetProperty (PropertyInfo pi) + { + return (PropertyBase)propertybuilder_to_property [pi]; + } + static public bool RegisterFieldBase (FieldBuilder fb, FieldBase f) { if (fieldbuilders_to_fields.Contains (fb)) @@ -1568,8 +1591,6 @@ public class TypeManager { return (FieldBase) fieldbuilders_to_fields [fb]; } - static Hashtable events; - static public void RegisterEvent (MyEventBuilder eb, MethodBase add, MethodBase remove) { if (events == null) @@ -1698,14 +1719,12 @@ public class TypeManager { /// This expands in context like: IA; IB : IA; IC : IA, IB; the interface "IC" to /// be IA, IB, IC. /// - public static Type[] ExpandInterfaces (EmitContext ec, TypeExpr [] base_interfaces) + public static Type[] ExpandInterfaces (TypeExpr [] base_interfaces) { ArrayList new_ifaces = new ArrayList (); foreach (TypeExpr iface in base_interfaces){ - Type itype = iface.ResolveType (ec); - if (itype == null) - return null; + Type itype = iface.Type; if (!new_ifaces.Contains (itype)) new_ifaces.Add (itype); @@ -1730,7 +1749,6 @@ public class TypeManager { /// public static Type [] GetInterfaces (Type t) { - Type [] cached = iface_cache [t] as Type []; if (cached != null) return cached; @@ -1752,13 +1770,13 @@ public class TypeManager { Type [] base_ifaces; if (t.BaseType == null) - base_ifaces = NoTypes; + base_ifaces = Type.EmptyTypes; else base_ifaces = GetInterfaces (t.BaseType); Type [] type_ifaces = (Type []) builder_to_ifaces [t]; - if (type_ifaces == null) - type_ifaces = NoTypes; - + if (type_ifaces == null || type_ifaces.Length == 0) + type_ifaces = Type.EmptyTypes; + int base_count = base_ifaces.Length; Type [] result = new Type [base_count + type_ifaces.Length]; base_ifaces.CopyTo (result, 0); @@ -2107,6 +2125,18 @@ public class TypeManager { } + // This method always return false for non-generic compiler, + // while Type.IsGenericParameter is returned if it is supported. + public static bool IsGenericParameter (Type type) + { + return false; + } + + public static int GenericParameterPosition (Type type) + { + throw new InternalErrorException ("should not be called"); + } + #region MemberLookup implementation // @@ -2114,11 +2144,6 @@ public class TypeManager { // uses NonPublic for both protected and private), we need to distinguish. // - static internal bool FilterNone (MemberInfo m, object filter_criteria) - { - return true; - } - internal class Closure { internal bool private_ok; @@ -2427,9 +2452,9 @@ public class TypeManager { return (MemberInfo []) first_members_list; } - if (method_list != null && method_list.Count > 0) + if (method_list != null && method_list.Count > 0) { return (MemberInfo []) method_list.ToArray (typeof (MemberInfo)); - + } // // This happens if we already used the cache in the first iteration, in this case // the cache already looked in all interfaces.