Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@gnome.org>2007-11-17 23:01:57 +0300
committerMiguel de Icaza <miguel@gnome.org>2007-11-17 23:01:57 +0300
commit4b075a596fb0989c902b74f4632356ba18c32b1e (patch)
tree00e63d7aa1e1624a9b2320d3e74bbd0cd3fede13 /mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs
parent0eb1105589b46e4881faf3090e710f83142177da (diff)
2007-11-17 Miguel de Icaza <miguel@novell.com>
* SignatureHelper.cs: Preparational tasks to support the AddArgument overloads that allow the specification of modopts and modreqs. Refactor code, add new parameters. svn path=/trunk/mcs/; revision=89871
Diffstat (limited to 'mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs')
-rw-r--r--mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs117
1 files changed, 83 insertions, 34 deletions
diff --git a/mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs b/mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs
index 2606a432271..1a7eb2316cd 100644
--- a/mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs
+++ b/mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs
@@ -58,6 +58,8 @@ namespace System.Reflection.Emit {
private Type returnType;
private CallingConventions callConv;
private CallingConvention unmanagedCallConv;
+ private Type[][] modreqs;
+ private Type[][] modopts;
internal SignatureHelper (ModuleBuilder module, SignatureHelperType type)
{
@@ -121,7 +123,56 @@ namespace System.Reflection.Emit {
throw new NotImplementedException ();
}
+ //
+ // Grows the given array, and returns the index where the element
+ // was added
+ //
+ static int AppendArray (ref Type [] array, Type t)
+ {
+ if (array != null) {
+ Type[] new_a = new Type [array.Length + 1];
+ System.Array.Copy (array, new_a, array.Length);
+ new_a [array.Length] = t;
+ array = new_a;
+ return array.Length;
+ } else {
+ array = new Type [1];
+ array [0] = t;
+ return 0;
+ }
+ }
+
#if NET_2_0
+ //
+ // Appends the given type array @t into the @array passed at
+ // position @pos. If there is no array, it gets created
+ //
+ // This allows adding data to a null array at position 5 for
+ // example, creating 4 empty slots before the slot where @t
+ // is stored.
+ //
+ //
+ static void AppendArrayAt (ref Type [][] array, Type [] t, int pos)
+ {
+ int top = Math.Max (pos, array == null ? 0 : array.Length);
+ Type[][] new_a = new Type [top+1][];
+ if (array != null)
+ System.Array.Copy (array, new_a, top);
+ new_a [pos] = t;
+ array = new_a;
+ }
+
+ static void ValidateParameterModifiers(string name, Type [] parameter_modifiers)
+ {
+ foreach (Type modifier in parameter_modifiers){
+ if (modifier == null)
+ throw new ArgumentNullException (name);
+ if (modifier.IsArray)
+ throw new ArgumentException (Locale.GetText ("Array type not permitted"), name);
+ if (modifier.ContainsGenericParameters)
+ throw new ArgumentException (Locale.GetText ("Open Generic Type not permitted"), name);
+ }
+ }
static void ValidateCustomModifier (int n, Type [][] custom_modifiers, string name)
{
@@ -137,15 +188,8 @@ namespace System.Reflection.Emit {
foreach (Type [] parameter_modifiers in custom_modifiers){
if (parameter_modifiers == null)
continue;
-
- foreach (Type modififier in parameter_modifiers){
- if (modififier == null)
- throw new ArgumentNullException (name);
- if (modififier.IsArray)
- throw new ArgumentException (Locale.GetText ("Array type not permitted"), name);
- if (modififier.ContainsGenericParameters)
- throw new ArgumentException (Locale.GetText ("Open Generic Type not permitted"), name);
- }
+
+ ValidateParameterModifiers (name, parameter_modifiers);
}
}
@@ -167,12 +211,36 @@ namespace System.Reflection.Emit {
ValidateCustomModifier (arguments.Length, requiredCustomModifiers, "requiredCustomModifiers");
ValidateCustomModifier (arguments.Length, optionalCustomModifiers, "optionalCustomModifiers");
-
- foreach (Type t in arguments){
- AddArgument (t);
+
+ for (int i = 0; i < arguments.Length; i++){
+ AddArgument (arguments [i],
+ requiredCustomModifiers != null ? requiredCustomModifiers [i] : null,
+ optionalCustomModifiers != null ? optionalCustomModifiers [i] : null);
}
}
+ [MonoTODO ("pinned is ignored")]
+ public void AddArgument (Type argument, bool pinned)
+ {
+ AddArgument (argument);
+ }
+
+ [MonoTODO ("not implemented")]
+ public void AddArgument (Type argument, Type [] requiredCustomModifiers, Type [] optionalCustomModifiers)
+ {
+ if (argument == null)
+ throw new ArgumentNullException ("argument");
+
+ ValidateParameterModifiers ("requiredCustomModifiers", requiredCustomModifiers);
+ ValidateParameterModifiers ("optionalCustomModifiers", optionalCustomModifiers);
+
+ int p = AppendArray (ref arguments, argument);
+ if (requiredCustomModifiers != null)
+ AppendArrayAt (ref modreqs, requiredCustomModifiers, p);
+ if (optionalCustomModifiers != null)
+ AppendArrayAt (ref modopts, optionalCustomModifiers, p);
+ }
+
[MonoTODO("Not implemented")]
public static SignatureHelper GetPropertySigHelper (Module mod, Type returnType,
Type [] requiredReturnTypeCustomModifiers,
@@ -187,30 +255,11 @@ namespace System.Reflection.Emit {
public void AddArgument (Type clsArgument)
{
- if (arguments != null) {
- Type[] new_a = new Type [arguments.Length + 1];
- System.Array.Copy (arguments, new_a, arguments.Length);
- new_a [arguments.Length] = clsArgument;
- arguments = new_a;
- } else {
- arguments = new Type [1];
- arguments [0] = clsArgument;
- }
- }
-
-#if NET_2_0
- [MonoTODO ("pinned is ignored")]
- public void AddArgument (Type argument, bool pinned)
- {
- AddArgument (argument);
- }
+ if (clsArgument == null)
+ throw new ArgumentNullException ("argument");
- [MonoTODO ("not implemented")]
- public void AddArgument (Type argument, Type [] requiredCustomModifiers, Type [] optionalCustomModifiers)
- {
- throw new NotImplementedException ();
+ AppendArray (ref arguments, clsArgument);
}
-#endif
[MonoTODO("Not implemented")]
public void AddSentinel ()