Update mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng/RelaxngPattern.cs
[mono.git] / mcs / class / IKVM.Reflection / Reader / TypeDefImpl.cs
index 3eea35099a551afd5b7d54c271c24f0c82031fde..b04ecbc37f211ddc32c13929a9a54ea9d937f8dd 100644 (file)
@@ -43,6 +43,7 @@ namespace IKVM.Reflection.Reader
                        this.index = index;
                        this.typeName = module.GetString(module.TypeDef.records[index].TypeName);
                        this.typeNamespace = module.GetString(module.TypeDef.records[index].TypeNamespace);
+                       MarkEnumOrValueType(typeNamespace, typeName);
                }
 
                public override Type BaseType
@@ -65,31 +66,26 @@ namespace IKVM.Reflection.Reader
 
                public override EventInfo[] __GetDeclaredEvents()
                {
-                       int token = this.MetadataToken;
-                       // TODO use binary search?
-                       for (int i = 0; i < module.EventMap.records.Length; i++)
+                       foreach (int i in module.EventMap.Filter(this.MetadataToken))
                        {
-                               if (module.EventMap.records[i].Parent == token)
+                               int evt = module.EventMap.records[i].EventList - 1;
+                               int end = module.EventMap.records.Length > i + 1 ? module.EventMap.records[i + 1].EventList - 1 : module.Event.records.Length;
+                               EventInfo[] events = new EventInfo[end - evt];
+                               if (module.EventPtr.RowCount == 0)
                                {
-                                       int evt = module.EventMap.records[i].EventList - 1;
-                                       int end = module.EventMap.records.Length > i + 1 ? module.EventMap.records[i + 1].EventList - 1 : module.Event.records.Length;
-                                       EventInfo[] events = new EventInfo[end - evt];
-                                       if (module.EventPtr.RowCount == 0)
+                                       for (int j = 0; evt < end; evt++, j++)
                                        {
-                                               for (int j = 0; evt < end; evt++, j++)
-                                               {
-                                                       events[j] = new EventInfoImpl(module, this, evt);
-                                               }
+                                               events[j] = new EventInfoImpl(module, this, evt);
                                        }
-                                       else
+                               }
+                               else
+                               {
+                                       for (int j = 0; evt < end; evt++, j++)
                                        {
-                                               for (int j = 0; evt < end; evt++, j++)
-                                               {
-                                                       events[j] = new EventInfoImpl(module, this, module.EventPtr.records[evt] - 1);
-                                               }
+                                               events[j] = new EventInfoImpl(module, this, module.EventPtr.records[evt] - 1);
                                        }
-                                       return events;
                                }
+                               return events;
                        }
                        return Empty<EventInfo>.Array;
                }
@@ -118,19 +114,14 @@ namespace IKVM.Reflection.Reader
 
                public override Type[] __GetDeclaredInterfaces()
                {
-                       int token = this.MetadataToken;
                        List<Type> list = null;
-                       // TODO use binary search?
-                       for (int i = 0; i < module.InterfaceImpl.records.Length; i++)
+                       foreach (int i in module.InterfaceImpl.Filter(this.MetadataToken))
                        {
-                               if (module.InterfaceImpl.records[i].Class == token)
+                               if (list == null)
                                {
-                                       if (list == null)
-                                       {
-                                               list = new List<Type>();
-                                       }
-                                       list.Add(module.ResolveType(module.InterfaceImpl.records[i].Interface, this));
+                                       list = new List<Type>();
                                }
+                               list.Add(module.ResolveType(module.InterfaceImpl.records[i].Interface, this));
                        }
                        return Util.ToArray(list, Type.EmptyTypes);
                }
@@ -159,25 +150,21 @@ namespace IKVM.Reflection.Reader
 
                public override __MethodImplMap __GetMethodImplMap()
                {
+                       PopulateGenericArguments();
                        List<MethodInfo> bodies = new List<MethodInfo>();
                        List<List<MethodInfo>> declarations = new List<List<MethodInfo>>();
-                       int token = this.MetadataToken;
-                       // TODO use binary search?
-                       for (int i = 0; i < module.MethodImpl.records.Length; i++)
+                       foreach (int i in module.MethodImpl.Filter(this.MetadataToken))
                        {
-                               if (module.MethodImpl.records[i].Class == token)
+                               MethodInfo body = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodBody, typeArgs, null);
+                               int index = bodies.IndexOf(body);
+                               if (index == -1)
                                {
-                                       MethodInfo body = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodBody, typeArgs, null);
-                                       int index = bodies.IndexOf(body);
-                                       if (index == -1)
-                                       {
-                                               index = bodies.Count;
-                                               bodies.Add(body);
-                                               declarations.Add(new List<MethodInfo>());
-                                       }
-                                       MethodInfo declaration = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodDeclaration, typeArgs, null);
-                                       declarations[index].Add(declaration);
+                                       index = bodies.Count;
+                                       bodies.Add(body);
+                                       declarations.Add(new List<MethodInfo>());
                                }
+                               MethodInfo declaration = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodDeclaration, typeArgs, null);
+                               declarations[index].Add(declaration);
                        }
                        __MethodImplMap map = new __MethodImplMap();
                        map.TargetType = this;
@@ -194,7 +181,7 @@ namespace IKVM.Reflection.Reader
                {
                        int token = this.MetadataToken;
                        List<Type> list = new List<Type>();
-                       // TODO use binary search?
+                       // note that the NestedClass table is sorted on NestedClass, so we can't use binary search
                        for (int i = 0; i < module.NestedClass.records.Length; i++)
                        {
                                if (module.NestedClass.records[i].EnclosingClass == token)
@@ -207,31 +194,26 @@ namespace IKVM.Reflection.Reader
 
                public override PropertyInfo[] __GetDeclaredProperties()
                {
-                       int token = this.MetadataToken;
-                       // TODO use binary search?
-                       for (int i = 0; i < module.PropertyMap.records.Length; i++)
+                       foreach (int i in module.PropertyMap.Filter(this.MetadataToken))
                        {
-                               if (module.PropertyMap.records[i].Parent == token)
+                               int property = module.PropertyMap.records[i].PropertyList - 1;
+                               int end = module.PropertyMap.records.Length > i + 1 ? module.PropertyMap.records[i + 1].PropertyList - 1 : module.Property.records.Length;
+                               PropertyInfo[] properties = new PropertyInfo[end - property];
+                               if (module.PropertyPtr.RowCount == 0)
                                {
-                                       int property = module.PropertyMap.records[i].PropertyList - 1;
-                                       int end = module.PropertyMap.records.Length > i + 1 ? module.PropertyMap.records[i + 1].PropertyList - 1 : module.Property.records.Length;
-                                       PropertyInfo[] properties = new PropertyInfo[end - property];
-                                       if (module.PropertyPtr.RowCount == 0)
+                                       for (int j = 0; property < end; property++, j++)
                                        {
-                                               for (int j = 0; property < end; property++, j++)
-                                               {
-                                                       properties[j] = new PropertyInfoImpl(module, this, property);
-                                               }
+                                               properties[j] = new PropertyInfoImpl(module, this, property);
                                        }
-                                       else
+                               }
+                               else
+                               {
+                                       for (int j = 0; property < end; property++, j++)
                                        {
-                                               for (int j = 0; property < end; property++, j++)
-                                               {
-                                                       properties[j] = new PropertyInfoImpl(module, this, module.PropertyPtr.records[property] - 1);
-                                               }
+                                               properties[j] = new PropertyInfoImpl(module, this, module.PropertyPtr.records[property] - 1);
                                        }
-                                       return properties;
                                }
+                               return properties;
                        }
                        return Empty<PropertyInfo>.Array;
                }
@@ -296,16 +278,10 @@ namespace IKVM.Reflection.Reader
                        return typeArgs[index];
                }
 
-               public override Type[][] __GetGenericArgumentsOptionalCustomModifiers()
-               {
-                       PopulateGenericArguments();
-                       return Util.Copy(new Type[typeArgs.Length][]);
-               }
-
-               public override Type[][] __GetGenericArgumentsRequiredCustomModifiers()
+               public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
                {
                        PopulateGenericArguments();
-                       return Util.Copy(new Type[typeArgs.Length][]);
+                       return new CustomModifiers[typeArgs.Length];
                }
 
                public override bool IsGenericType
@@ -358,14 +334,9 @@ namespace IKVM.Reflection.Reader
                                {
                                        return null;
                                }
-                               // TODO use binary search (if sorted)
-                               int token = this.MetadataToken;
-                               for (int i = 0; i < module.NestedClass.records.Length; i++)
+                               foreach (int i in module.NestedClass.Filter(this.MetadataToken))
                                {
-                                       if (module.NestedClass.records[i].NestedClass == token)
-                                       {
-                                               return module.ResolveType(module.NestedClass.records[i].EnclosingClass, null, null);
-                                       }
+                                       return module.ResolveType(module.NestedClass.records[i].EnclosingClass, null, null);
                                }
                                throw new InvalidOperationException();
                        }
@@ -416,16 +387,11 @@ namespace IKVM.Reflection.Reader
 
                public override bool __GetLayout(out int packingSize, out int typeSize)
                {
-                       int token = this.MetadataToken;
-                       // TODO use binary search?
-                       for (int i = 0; i < module.ClassLayout.records.Length; i++)
+                       foreach (int i in module.ClassLayout.Filter(this.MetadataToken))
                        {
-                               if (module.ClassLayout.records[i].Parent == token)
-                               {
-                                       packingSize = module.ClassLayout.records[i].PackingSize;
-                                       typeSize = module.ClassLayout.records[i].ClassSize;
-                                       return true;
-                               }
+                               packingSize = module.ClassLayout.records[i].PackingSize;
+                               typeSize = module.ClassLayout.records[i].ClassSize;
+                               return true;
                        }
                        packingSize = 0;
                        typeSize = 0;
@@ -441,5 +407,17 @@ namespace IKVM.Reflection.Reader
                {
                        get { return index == 0; }
                }
+
+               internal override IList<CustomAttributeData> GetInterfaceImplCustomAttributes(Type interfaceType, Type attributeType)
+               {
+                       foreach (int i in module.InterfaceImpl.Filter(this.MetadataToken))
+                       {
+                               if (module.ResolveType(module.InterfaceImpl.records[i].Interface, this) == interfaceType)
+                               {
+                                       return module.GetCustomAttributes((InterfaceImplTable.Index << 24) | (i + 1), attributeType);
+                               }
+                       }
+                       return Empty<CustomAttributeData>.Array;
+               }
        }
 }