diff options
author | jfrijters <jfrijters> | 2011-12-01 13:47:21 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2011-12-01 13:47:21 +0400 |
commit | 8159a8d12c3db9a81774a7c7cb247f93346359ce (patch) | |
tree | fe556c5605013f8d0f7b8a51248852b369bca0e3 /reflect/Emit | |
parent | a1709bdbc80521975c606b1f73cd7cf619b6ec63 (diff) |
- Added custom modifier support in local variable signatures.
- Fixed SignatureHelper to support custom modifiers in method signatures.
Diffstat (limited to 'reflect/Emit')
-rw-r--r-- | reflect/Emit/ILGenerator.cs | 23 | ||||
-rw-r--r-- | reflect/Emit/SignatureHelper.cs | 9 |
2 files changed, 26 insertions, 6 deletions
diff --git a/reflect/Emit/ILGenerator.cs b/reflect/Emit/ILGenerator.cs index 437a4e3c..46c70918 100644 --- a/reflect/Emit/ILGenerator.cs +++ b/reflect/Emit/ILGenerator.cs @@ -152,6 +152,7 @@ namespace IKVM.Reflection.Emit private readonly ModuleBuilder moduleBuilder; private readonly ByteBuffer code; private readonly List<LocalBuilder> locals = new List<LocalBuilder>(); + private List<CustomModifiers> localCustomModifiers; private readonly List<int> tokenFixups = new List<int>(); private readonly List<int> labels = new List<int>(); private readonly List<int> labelStackHeight = new List<int>(); @@ -460,6 +461,26 @@ namespace IKVM.Reflection.Emit return local; } + public LocalBuilder __DeclareLocal(Type localType, bool pinned, CustomModifiers customModifiers) + { + if (!customModifiers.IsEmpty) + { + if (localCustomModifiers == null) + { + localCustomModifiers = new List<CustomModifiers>(); + } + // we lazily fill up the list (to sync with the locals list) and we don't need to + // make sure that the list has the same length as the locals list, because + // Signature.WriteLocalVarSig() can tolerate that. + while (localCustomModifiers.Count < locals.Count) + { + localCustomModifiers.Add(new CustomModifiers()); + } + localCustomModifiers.Add(customModifiers); + } + return DeclareLocal(localType, pinned); + } + public Label DefineLabel() { Label label = new Label(labels.Count); @@ -1034,7 +1055,7 @@ namespace IKVM.Reflection.Emit if (locals.Count != 0) { ByteBuffer localVarSig = new ByteBuffer(locals.Count + 2); - Signature.WriteLocalVarSig(moduleBuilder, localVarSig, locals); + Signature.WriteLocalVarSig(moduleBuilder, localVarSig, locals, localCustomModifiers); localVarSigTok = 0x11000000 | moduleBuilder.StandAloneSig.FindOrAddRecord(moduleBuilder.Blobs.Add(localVarSig)); } diff --git a/reflect/Emit/SignatureHelper.cs b/reflect/Emit/SignatureHelper.cs index 8162ef1e..b849371f 100644 --- a/reflect/Emit/SignatureHelper.cs +++ b/reflect/Emit/SignatureHelper.cs @@ -162,11 +162,11 @@ namespace IKVM.Reflection.Emit case 0: if (unmanaged) { - Signature.WriteStandAloneMethodSig(module, bb, __StandAloneMethodSig.Create(unmanagedCallConv, returnType, new CustomModifiers(), args.ToArray(), null)); + Signature.WriteStandAloneMethodSig(module, bb, __StandAloneMethodSig.Create(unmanagedCallConv, returnType, returnTypeCustomModifiers, args.ToArray(), customModifiers.ToArray())); } else { - Signature.WriteStandAloneMethodSig(module, bb, __StandAloneMethodSig.Create(callingConvention, returnType, new CustomModifiers(), args.ToArray(), optionalArgs.ToArray(), null)); + Signature.WriteStandAloneMethodSig(module, bb, __StandAloneMethodSig.Create(callingConvention, returnType, returnTypeCustomModifiers, args.ToArray(), optionalArgs.ToArray(), customModifiers.ToArray())); } break; case Signature.FIELD: @@ -176,7 +176,7 @@ namespace IKVM.Reflection.Emit Signature.WritePropertySig(module, bb, callingConvention, returnType, returnTypeCustomModifiers, args.ToArray(), customModifiers.ToArray()); break; case Signature.LOCAL_SIG: - Signature.WriteLocalVarSig(module, bb, locals); + Signature.WriteLocalVarSig(module, bb, locals, customModifiers); break; default: throw new InvalidOperationException(); @@ -209,7 +209,6 @@ namespace IKVM.Reflection.Emit { if (type == Signature.LOCAL_SIG) { - // TODO support custom modifiers in local sig locals.Add(new LocalBuilder(argument, 0, pinned)); } else if (optional) @@ -219,8 +218,8 @@ namespace IKVM.Reflection.Emit else { this.args.Add(argument); - this.customModifiers.Add(customModifiers); } + this.customModifiers.Add(customModifiers); } public void AddArguments(Type[] arguments, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers) |