Fix null sessions in HttpContextWrapper.Session
[mono.git] / mcs / class / IKVM.Reflection / Reader / GenericTypeParameter.cs
index 2f961f94d1c541bac5d59ec5258943dcaafdf551..d0c74052154cffe880b351ee08c46e0954c6db52 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2009 Jeroen Frijters
+  Copyright (C) 2009-2012 Jeroen Frijters
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -28,7 +28,7 @@ using IKVM.Reflection.Metadata;
 
 namespace IKVM.Reflection.Reader
 {
-       abstract class TypeParameterType : Type
+       abstract class TypeParameterType : TypeInfo
        {
                public sealed override string AssemblyQualifiedName
                {
@@ -73,11 +73,6 @@ namespace IKVM.Reflection.Reader
                        get { return TypeAttributes.Public; }
                }
 
-               public sealed override Type UnderlyingSystemType
-               {
-                       get { return this; }
-               }
-
                public sealed override string FullName
                {
                        get { return null; }
@@ -92,6 +87,59 @@ namespace IKVM.Reflection.Reader
                {
                        get { return true; }
                }
+
+               public sealed override bool __ContainsMissingType
+               {
+                       get
+                       {
+                               bool freeList = false;
+                               try
+                               {
+                                       foreach (Type type in GetGenericParameterConstraints())
+                                       {
+                                               if (type.__IsMissing)
+                                               {
+                                                       return true;
+                                               }
+                                               else if (type.IsConstructedGenericType || type.HasElementType || type.__IsFunctionPointer)
+                                               {
+                                                       // if a constructed type contains generic parameters,
+                                                       // it might contain this type parameter again and
+                                                       // to prevent infinite recurssion, we keep a thread local
+                                                       // list of type parameters we've already processed
+                                                       if (type.ContainsGenericParameters)
+                                                       {
+                                                               if (containsMissingTypeHack == null)
+                                                               {
+                                                                       freeList = true;
+                                                                       containsMissingTypeHack = new List<Type>();
+                                                               }
+                                                               else if (containsMissingTypeHack.Contains(this))
+                                                               {
+                                                                       return false;
+                                                               }
+                                                               containsMissingTypeHack.Add(this);
+                                                       }
+                                                       if (type.__ContainsMissingType)
+                                                       {
+                                                               return true;
+                                                       }
+                                               }
+                                       }
+                                       return false;
+                               }
+                               finally
+                               {
+                                       if (freeList)
+                                       {
+                                               containsMissingTypeHack = null;
+                                       }
+                               }
+                       }
+               }
+
+               [ThreadStatic]
+               private static List<Type> containsMissingTypeHack;
        }
 
        sealed class UnboundGenericMethodParameter : TypeParameterType
@@ -99,13 +147,23 @@ namespace IKVM.Reflection.Reader
                private static readonly DummyModule module = new DummyModule();
                private readonly int position;
 
-               private sealed class DummyModule : Module
+               private sealed class DummyModule : NonPEModule
                {
                        internal DummyModule()
                                : base(new Universe())
                        {
                        }
 
+                       protected override Exception NotSupportedException()
+                       {
+                               return new InvalidOperationException();
+                       }
+
+                       protected override Exception ArgumentOutOfRangeException()
+                       {
+                               return new InvalidOperationException();
+                       }
+
                        public override bool Equals(object obj)
                        {
                                throw new InvalidOperationException();
@@ -131,7 +189,12 @@ namespace IKVM.Reflection.Reader
                                get { throw new InvalidOperationException(); }
                        }
 
-                       internal override Type GetTypeImpl(string typeName)
+                       internal override Type FindType(TypeName typeName)
+                       {
+                               throw new InvalidOperationException();
+                       }
+
+                       internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
                        {
                                throw new InvalidOperationException();
                        }
@@ -156,60 +219,15 @@ namespace IKVM.Reflection.Reader
                                get { throw new InvalidOperationException(); }
                        }
 
-                       public override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       public override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       public override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       public override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       public override string ResolveString(int metadataToken)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       public override Type[] __ResolveOptionalParameterTypes(int metadataToken)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
                        public override string ScopeName
                        {
                                get { throw new InvalidOperationException(); }
                        }
-
-                       public override AssemblyName[] __GetReferencedAssemblies()
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       internal override Type GetModuleType()
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       internal override ByteReader GetBlob(int blobIndex)
-                       {
-                               throw new InvalidOperationException();
-                       }
                }
 
                internal static Type Make(int position)
                {
-                       return module.CanonicalizeType(new UnboundGenericMethodParameter(position));
+                       return module.universe.CanonicalizeType(new UnboundGenericMethodParameter(position));
                }
 
                private UnboundGenericMethodParameter(int position)
@@ -277,6 +295,11 @@ namespace IKVM.Reflection.Reader
                {
                        return binder.BindMethodParameter(this);
                }
+
+               internal override bool IsBaked
+               {
+                       get { throw new InvalidOperationException(); }
+               }
        }
 
        sealed class GenericTypeParameter : TypeParameterType
@@ -347,14 +370,9 @@ namespace IKVM.Reflection.Reader
                {
                        IGenericContext context = (this.DeclaringMethod as IGenericContext) ?? this.DeclaringType;
                        List<Type> list = new List<Type>();
-                       int token = this.MetadataToken;
-                       // TODO use binary search
-                       for (int i = 0; i < module.GenericParamConstraint.records.Length; i++)
+                       foreach (int i in module.GenericParamConstraint.Filter(this.MetadataToken))
                        {
-                               if (module.GenericParamConstraint.records[i].Owner == token)
-                               {
-                                       list.Add(module.ResolveType(module.GenericParamConstraint.records[i].Constraint, context));
-                               }
+                               list.Add(module.ResolveType(module.GenericParamConstraint.records[i].Constraint, context));
                        }
                        return list.ToArray();
                }
@@ -376,5 +394,10 @@ namespace IKVM.Reflection.Reader
                                return binder.BindTypeParameter(this);
                        }
                }
+
+               internal override bool IsBaked
+               {
+                       get { return true; }
+               }
        }
 }