New tests.
[mono.git] / mcs / mcs / support.cs
index 433012e90f4016dc2691c744704ad8d485f4a18e..8fcb5bf6081b058042eb984fdb684167c9412570 100644 (file)
@@ -20,7 +20,7 @@ using System.Collections.Generic;
 
 namespace Mono.CSharp {
 
-       class ReferenceEquality<T> : IEqualityComparer<T> where T : class
+       sealed class ReferenceEquality<T> : IEqualityComparer<T> where T : class
        {
                public static readonly IEqualityComparer<T> Default = new ReferenceEquality<T> ();
 
@@ -30,16 +30,16 @@ namespace Mono.CSharp {
 
                public bool Equals (T x, T y)
                {
-                       return object.ReferenceEquals (x, y);
+                       return ReferenceEquals (x, y);
                }
 
                public int GetHashCode (T obj)
                {
-                       return obj == null ? 0 : obj.GetHashCode ();
+                       return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode (obj);
                }
        }
 
-       class Tuple<T1, T2>
+       class Tuple<T1, T2> : IEquatable<Tuple<T1, T2>>
        {
                public Tuple (T1 item1, T2 item2)
                {
@@ -49,6 +49,29 @@ namespace Mono.CSharp {
 
                public T1 Item1 { get; private set; }
                public T2 Item2 { get; private set; }
+
+               public override int GetHashCode ()
+               {
+                       return Item1.GetHashCode () ^ Item2.GetHashCode ();
+               }
+
+               #region IEquatable<Tuple<T1,T2>> Members
+
+               public bool Equals (Tuple<T1, T2> other)
+               {
+                       return EqualityComparer<T1>.Default.Equals (Item1, other.Item1) &&
+                               EqualityComparer<T2>.Default.Equals (Item2, other.Item2);
+               }
+
+               #endregion
+       }
+
+       static class Tuple
+       {
+               public static Tuple<T1, T2> Create<T1, T2> (T1 item1, T2 item2)
+               {
+                       return new Tuple<T1, T2> (item1, item2);
+               }
        }
 
        public class Accessors {
@@ -254,489 +277,6 @@ namespace Mono.CSharp {
                }
        }
 
-       class PartialMethodDefinitionInfo : MethodInfo
-       {
-               MethodOrOperator mc;
-               MethodAttributes attrs;
-
-               public PartialMethodDefinitionInfo (MethodOrOperator mc)
-               {
-                       this.mc = mc;
-                       if ((mc.ModFlags & Modifiers.STATIC) != 0)
-                               attrs = MethodAttributes.Static;
-               }
-
-               public override MethodInfo GetBaseDefinition ()
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override ICustomAttributeProvider ReturnTypeCustomAttributes
-               {
-                       get { throw new NotImplementedException (); }
-               }
-
-               public override MethodAttributes Attributes
-               {
-                       get { return attrs; }
-               }
-
-               public override MethodImplAttributes GetMethodImplementationFlags ()
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override ParameterInfo [] GetParameters ()
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override object Invoke (object obj, BindingFlags invokeAttr, Binder binder, object [] parameters, CultureInfo culture)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override RuntimeMethodHandle MethodHandle
-               {
-                       get { throw new NotImplementedException (); }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return mc.Parent.TypeBuilder; }
-               }
-
-               public override object [] GetCustomAttributes (Type attributeType, bool inherit)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override object [] GetCustomAttributes (bool inherit)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type ReturnType {
-                       get {
-                               return mc.MemberType;
-                       }
-               }
-
-               public override bool IsDefined (Type attributeType, bool inherit)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override string Name
-               {
-                       get { return mc.Name; }
-               }
-
-               public override Type ReflectedType
-               {
-                       get { throw new NotImplementedException (); }
-               }
-       }
-
-#if NET_4_0 || MS_COMPATIBLE
-       [System.Diagnostics.DebuggerDisplay ("Dynamic type")]
-#endif
-       class DynamicType : Type
-       {
-               public override Assembly Assembly {
-                       get { return UnderlyingSystemType.Assembly; }
-               }
-
-               public override string AssemblyQualifiedName {
-                       get { throw new NotImplementedException (); }
-               }
-
-               public override Type BaseType {
-                       get { return null; }
-               }
-
-               public override string FullName {
-                       get { return UnderlyingSystemType.FullName; }
-               }
-
-               public override Guid GUID {
-                       get { throw new NotImplementedException (); }
-               }
-
-               protected override TypeAttributes GetAttributeFlagsImpl ()
-               {
-                       return UnderlyingSystemType.Attributes;
-               }
-
-               protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type GetElementType ()
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override EventInfo[] GetEvents (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override FieldInfo GetField (string name, BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override FieldInfo[] GetFields (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type GetInterface (string name, bool ignoreCase)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type[] GetInterfaces ()
-               {
-                       return Type.EmptyTypes;
-               }
-
-               public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type GetNestedType (string name, BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type[] GetNestedTypes (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               protected override bool HasElementTypeImpl ()
-               {
-                       return false;
-               }
-
-               public override object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               protected override bool IsArrayImpl ()
-               {
-                       return false;
-               }
-
-               protected override bool IsByRefImpl ()
-               {
-                       return false;
-               }
-
-               protected override bool IsCOMObjectImpl ()
-               {
-                       return false;
-               }
-
-               protected override bool IsPointerImpl ()
-               {
-                       return false;
-               }
-
-               protected override bool IsPrimitiveImpl ()
-               {
-                       return false;
-               }
-
-               public override Module Module {
-                       get { return UnderlyingSystemType.Module; }
-               }
-
-               public override string Namespace {
-                       get { return UnderlyingSystemType.Namespace; }
-               }
-
-               public override Type UnderlyingSystemType {
-                       get { return TypeManager.object_type; }
-               }
-
-               public override object[] GetCustomAttributes (Type attributeType, bool inherit)
-               {
-                       return new object [0];
-               }
-
-               public override object[] GetCustomAttributes (bool inherit)
-               {
-                       return new object [0];
-               }
-
-               public override bool IsDefined (Type attributeType, bool inherit)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override string Name {
-                       get { return UnderlyingSystemType.Name; }
-               }
-
-               public override string ToString ()
-               {
-                       return UnderlyingSystemType.ToString ();
-               }
-
-               public override RuntimeTypeHandle TypeHandle {
-                       get { return UnderlyingSystemType.TypeHandle; }
-               }
-
-               public override Type MakeByRefType ()
-               {
-                       // TODO: Wrong, hides dynamic type
-                       return UnderlyingSystemType.MakeByRefType ();
-               }
-       }
-
-#if NET_4_0 || MS_COMPATIBLE
-       [System.Diagnostics.DebuggerDisplay ("Dynamic array type")]
-#endif
-       class DynamicArrayType : Type
-       {
-               readonly int rank;
-               Type reflection_type;
-
-               public DynamicArrayType (int rank)
-               {
-                       this.rank = rank;
-               }
-
-               public override Assembly Assembly {
-                       get { return UnderlyingSystemType.Assembly; }
-               }
-
-               public override string AssemblyQualifiedName {
-                       get { throw new NotImplementedException (); }
-               }
-
-               public override Type BaseType {
-                       get { return TypeManager.array_type; }
-               }
-
-               public override string FullName {
-                       get { return UnderlyingSystemType.FullName; }
-               }
-
-               public override Guid GUID {
-                       get { throw new NotImplementedException (); }
-               }
-
-               protected override TypeAttributes GetAttributeFlagsImpl ()
-               {
-                       return UnderlyingSystemType.Attributes;
-               }
-
-               public override int GetArrayRank ()
-               {
-                       return rank;
-               }
-
-               protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type GetElementType ()
-               {
-                       return InternalType.Dynamic;
-               }
-
-               public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override EventInfo[] GetEvents (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override FieldInfo GetField (string name, BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override FieldInfo[] GetFields (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type GetInterface (string name, bool ignoreCase)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type[] GetInterfaces ()
-               {
-                       return Type.EmptyTypes;
-               }
-
-               public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type GetNestedType (string name, BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override Type[] GetNestedTypes (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               protected override bool HasElementTypeImpl ()
-               {
-                       return true;
-               }
-
-               public override object InvokeMember (string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               protected override bool IsArrayImpl ()
-               {
-                       return true;
-               }
-
-               protected override bool IsByRefImpl ()
-               {
-                       return false;
-               }
-
-               protected override bool IsCOMObjectImpl ()
-               {
-                       return false;
-               }
-
-               protected override bool IsPointerImpl ()
-               {
-                       return false;
-               }
-
-               protected override bool IsPrimitiveImpl ()
-               {
-                       return false;
-               }
-
-               public override Module Module {
-                       get { return UnderlyingSystemType.Module; }
-               }
-
-               public override string Namespace {
-                       get { return UnderlyingSystemType.Namespace; }
-               }
-
-               public override Type UnderlyingSystemType {
-                       get {
-                               if (reflection_type == null) {
-                                       reflection_type = rank == 1 ?
-                                               TypeManager.object_type.MakeArrayType () :
-                                               TypeManager.object_type.MakeArrayType (rank);
-                               }
-
-                               return reflection_type;
-                       }
-               }
-
-               public override object[] GetCustomAttributes (Type attributeType, bool inherit)
-               {
-                       return new object [0];
-               }
-
-               public override object[] GetCustomAttributes (bool inherit)
-               {
-                       return new object [0];
-               }
-
-               public override bool IsDefined (Type attributeType, bool inherit)
-               {
-                       throw new NotImplementedException ();
-               }
-
-               public override string Name {
-                       get { return UnderlyingSystemType.Name; }
-               }
-
-               public override string ToString ()
-               {
-                       return UnderlyingSystemType.ToString ();
-               }
-
-               public override RuntimeTypeHandle TypeHandle {
-                       get { return UnderlyingSystemType.TypeHandle; }
-               }
-       }
-
        public class UnixUtils {
                [System.Runtime.InteropServices.DllImport ("libc", EntryPoint="isatty")]
                extern static int _isatty (int fd);