Update mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng/RelaxngPattern.cs
[mono.git] / mcs / class / IKVM.Reflection / PropertySignature.cs
index de342decd6c0c3caff5e17416f17d8dbe37d6fb3..9a4a5534d129d6cf569ca94a1941385c299e49b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2009 Jeroen Frijters
+  Copyright (C) 2009-2011 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
@@ -35,26 +35,20 @@ namespace IKVM.Reflection
        {
                private CallingConventions callingConvention;
                private readonly Type propertyType;
-               private readonly Type[] optionalCustomModifiers;
-               private readonly Type[] requiredCustomModifiers;
                private readonly Type[] parameterTypes;
-               private readonly Type[][] parameterOptionalCustomModifiers;
-               private readonly Type[][] parameterRequiredCustomModifiers;
+               private readonly PackedCustomModifiers customModifiers;
 
-               internal static PropertySignature Create(CallingConventions callingConvention, Type propertyType, Type[] optionalCustomModifiers, Type[] requiredCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeOptionalCustomModifiers, Type[][] parameterTypeRequiredCustomModifiers)
+               internal static PropertySignature Create(CallingConventions callingConvention, Type propertyType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
                {
-                       return new PropertySignature(callingConvention, propertyType, Util.Copy(optionalCustomModifiers), Util.Copy(requiredCustomModifiers), Util.Copy(parameterTypes), Util.Copy(parameterTypeOptionalCustomModifiers), Util.Copy(parameterTypeRequiredCustomModifiers));
+                       return new PropertySignature(callingConvention, propertyType, Util.Copy(parameterTypes), customModifiers);
                }
 
-               private PropertySignature(CallingConventions callingConvention, Type propertyType, Type[] optionalCustomModifiers, Type[] requiredCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeOptionalCustomModifiers, Type[][] parameterTypeRequiredCustomModifiers)
+               private PropertySignature(CallingConventions callingConvention, Type propertyType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
                {
                        this.callingConvention = callingConvention;
                        this.propertyType = propertyType;
-                       this.optionalCustomModifiers = optionalCustomModifiers;
-                       this.requiredCustomModifiers = requiredCustomModifiers;
                        this.parameterTypes = parameterTypes;
-                       this.parameterOptionalCustomModifiers = parameterTypeOptionalCustomModifiers;
-                       this.parameterRequiredCustomModifiers = parameterTypeRequiredCustomModifiers;
+                       this.customModifiers = customModifiers;
                }
 
                public override bool Equals(object obj)
@@ -62,13 +56,12 @@ namespace IKVM.Reflection
                        PropertySignature other = obj as PropertySignature;
                        return other != null
                                && other.propertyType.Equals(propertyType)
-                               && Util.ArrayEquals(other.optionalCustomModifiers, optionalCustomModifiers)
-                               && Util.ArrayEquals(other.requiredCustomModifiers, requiredCustomModifiers);
+                               && other.customModifiers.Equals(customModifiers);
                }
 
                public override int GetHashCode()
                {
-                       return propertyType.GetHashCode() ^ Util.GetHashCode(optionalCustomModifiers) ^ Util.GetHashCode(requiredCustomModifiers);
+                       return propertyType.GetHashCode() ^ customModifiers.GetHashCode();
                }
 
                internal int ParameterCount
@@ -96,14 +89,9 @@ namespace IKVM.Reflection
                        get { return propertyType; }
                }
 
-               internal Type[] GetOptionalCustomModifiers()
+               internal CustomModifiers GetCustomModifiers()
                {
-                       return Util.Copy(optionalCustomModifiers);
-               }
-
-               internal Type[] GetRequiredCustomModifiers()
-               {
-                       return Util.Copy(requiredCustomModifiers);
+                       return customModifiers.GetReturnTypeCustomModifiers();
                }
 
                internal PropertySignature ExpandTypeParameters(Type declaringType)
@@ -111,11 +99,8 @@ namespace IKVM.Reflection
                        return new PropertySignature(
                                callingConvention,
                                propertyType.BindTypeParameters(declaringType),
-                               BindTypeParameters(declaringType, optionalCustomModifiers),
-                               BindTypeParameters(declaringType, requiredCustomModifiers),
                                BindTypeParameters(declaringType, parameterTypes),
-                               BindTypeParameters(declaringType, parameterOptionalCustomModifiers),
-                               BindTypeParameters(declaringType, parameterRequiredCustomModifiers));
+                               customModifiers.Bind(declaringType));
                }
 
                internal override void WriteSig(ModuleBuilder module, ByteBuffer bb)
@@ -135,21 +120,13 @@ namespace IKVM.Reflection
                        }
                        bb.Write(flags);
                        bb.WriteCompressedInt(parameterTypes == null ? 0 : parameterTypes.Length);
-                       WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, requiredCustomModifiers);
-                       WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, optionalCustomModifiers);
+                       WriteCustomModifiers(module, bb, customModifiers.GetReturnTypeCustomModifiers());
                        WriteType(module, bb, propertyType);
                        if (parameterTypes != null)
                        {
                                for (int i = 0; i < parameterTypes.Length; i++)
                                {
-                                       if (parameterRequiredCustomModifiers != null)
-                                       {
-                                               WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_REQD, parameterRequiredCustomModifiers[i]);
-                                       }
-                                       if (parameterOptionalCustomModifiers != null)
-                                       {
-                                               WriteCustomModifiers(module, bb, ELEMENT_TYPE_CMOD_OPT, parameterOptionalCustomModifiers[i]);
-                                       }
+                                       WriteCustomModifiers(module, bb, customModifiers.GetParameterCustomModifiers(i));
                                        WriteType(module, bb, parameterTypes[i]);
                                }
                        }
@@ -160,19 +137,19 @@ namespace IKVM.Reflection
                        return parameterTypes[parameter];
                }
 
-               internal Type[] GetOptionalCustomModifiers(int parameter)
+               internal CustomModifiers GetParameterCustomModifiers(int parameter)
                {
-                       return parameterOptionalCustomModifiers == null ? Type.EmptyTypes : parameterOptionalCustomModifiers[parameter];
+                       return customModifiers.GetParameterCustomModifiers(parameter);
                }
 
-               internal Type[] GetRequiredCustomModifiers(int parameter)
+               internal CallingConventions CallingConvention
                {
-                       return parameterRequiredCustomModifiers == null ? Type.EmptyTypes : parameterRequiredCustomModifiers[parameter];
+                       get { return callingConvention; }
                }
 
-               internal CallingConventions CallingConvention
+               internal bool MatchParameterTypes(Type[] types)
                {
-                       get { return callingConvention; }
+                       return Util.ArrayEquals(types, parameterTypes);
                }
 
                internal static PropertySignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
@@ -192,32 +169,18 @@ namespace IKVM.Reflection
                                callingConvention |= CallingConventions.ExplicitThis;
                        }
                        Type returnType;
-                       Type[] returnTypeRequiredCustomModifiers;
-                       Type[] returnTypeOptionalCustomModifiers;
                        Type[] parameterTypes;
-                       Type[][] parameterRequiredCustomModifiers;
-                       Type[][] parameterOptionalCustomModifiers;
                        int paramCount = br.ReadCompressedInt();
-                       ReadCustomModifiers(module, br, context, out returnTypeRequiredCustomModifiers, out returnTypeOptionalCustomModifiers);
+                       CustomModifiers[] mods = null;
+                       PackedCustomModifiers.Pack(ref mods, 0, CustomModifiers.Read(module, br, context), paramCount + 1);
                        returnType = ReadRetType(module, br, context);
                        parameterTypes = new Type[paramCount];
-                       parameterRequiredCustomModifiers = null;
-                       parameterOptionalCustomModifiers = null;
                        for (int i = 0; i < parameterTypes.Length; i++)
                        {
-                               if (IsCustomModifier(br.PeekByte()))
-                               {
-                                       if (parameterOptionalCustomModifiers == null)
-                                       {
-                                               parameterOptionalCustomModifiers = new Type[parameterTypes.Length][];
-                                               parameterRequiredCustomModifiers = new Type[parameterTypes.Length][];
-                                       }
-                                       ReadCustomModifiers(module, br, context, out parameterRequiredCustomModifiers[i], out parameterOptionalCustomModifiers[i]);
-                               }
+                               PackedCustomModifiers.Pack(ref mods, i + 1, CustomModifiers.Read(module, br, context), paramCount + 1);
                                parameterTypes[i] = ReadParam(module, br, context);
                        }
-                       return new PropertySignature(callingConvention, returnType, returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
-                               parameterTypes, parameterOptionalCustomModifiers, parameterRequiredCustomModifiers);
+                       return new PropertySignature(callingConvention, returnType, parameterTypes, PackedCustomModifiers.Wrap(mods));
                }
        }
 }