Skip to content

Commit 1a49a57

Browse files
committed
Add missing Copy logic for Array element values.
1 parent 6855d54 commit 1a49a57

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

src/IKVM.ByteCode/Decoding/ArrayElementValue.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Collections;
44
using System.Collections.Generic;
55

6+
using IKVM.ByteCode.Encoding;
7+
68
namespace IKVM.ByteCode.Decoding
79
{
810

@@ -121,6 +123,78 @@ public static bool TryRead(ref ClassFormatReader reader, out ArrayElementValue v
121123
return true;
122124
}
123125

126+
/// <summary>
127+
/// Copies this annotation to the encoder.
128+
/// </summary>
129+
/// <typeparam name="TConstantView"></typeparam>
130+
/// <typeparam name="TConstantPool"></typeparam>
131+
/// <param name="constantView"></param>
132+
/// <param name="constantPool"></param>
133+
/// <param name="encoder"></param>
134+
public readonly void CopyTo<TConstantView, TConstantPool>(TConstantView constantView, TConstantPool constantPool, ref ElementValueTableEncoder encoder)
135+
where TConstantView : IConstantView
136+
where TConstantPool : IConstantPool
137+
{
138+
foreach (var i in this)
139+
{
140+
switch (i.Kind)
141+
{
142+
case ElementValueKind.Byte:
143+
var _byte = i.AsConstant();
144+
encoder.Byte(constantPool.Get(constantView.Get((IntegerConstantHandle)_byte.Handle)));
145+
break;
146+
case ElementValueKind.Char:
147+
var _char = i.AsConstant();
148+
encoder.Char(constantPool.Get(constantView.Get((IntegerConstantHandle)_char.Handle)));
149+
break;
150+
case ElementValueKind.Double:
151+
var _double = i.AsConstant();
152+
encoder.Double(constantPool.Get(constantView.Get((DoubleConstantHandle)_double.Handle)));
153+
break;
154+
case ElementValueKind.Float:
155+
var _float = i.AsConstant();
156+
encoder.Float(constantPool.Get(constantView.Get((FloatConstantHandle)_float.Handle)));
157+
break;
158+
case ElementValueKind.Integer:
159+
var _integer = i.AsConstant();
160+
encoder.Integer(constantPool.Get(constantView.Get((IntegerConstantHandle)_integer.Handle)));
161+
break;
162+
case ElementValueKind.Long:
163+
var _long = i.AsConstant();
164+
encoder.Long(constantPool.Get(constantView.Get((LongConstantHandle)_long.Handle)));
165+
break;
166+
case ElementValueKind.Short:
167+
var _short = i.AsConstant();
168+
encoder.Short(constantPool.Get(constantView.Get((IntegerConstantHandle)_short.Handle)));
169+
break;
170+
case ElementValueKind.Boolean:
171+
var _boolean = i.AsConstant();
172+
encoder.Boolean(constantPool.Get(constantView.Get((IntegerConstantHandle)_boolean.Handle)));
173+
break;
174+
case ElementValueKind.String:
175+
var _string = i.AsConstant();
176+
encoder.String(constantPool.Get(constantView.Get((Utf8ConstantHandle)_string.Handle)));
177+
break;
178+
case ElementValueKind.Enum:
179+
var _enum = i.AsEnum();
180+
encoder.Enum(constantPool.Get(constantView.Get(_enum.TypeName)), constantPool.Get(constantView.Get(_enum.ConstantName)));
181+
break;
182+
case ElementValueKind.Class:
183+
var _class = i.AsClass();
184+
encoder.Class(constantPool.Get(constantView.Get(_class.Class)));
185+
break;
186+
case ElementValueKind.Annotation:
187+
var _annotation = i.AsAnnotation();
188+
encoder.Annotation(e => _annotation.Annotation.CopyTo(constantView, constantPool, ref e));
189+
break;
190+
case ElementValueKind.Array:
191+
var _array = i.AsArray();
192+
encoder.Array(e => _array.CopyTo(constantView, constantPool, ref e));
193+
break;
194+
}
195+
}
196+
}
197+
124198
readonly ElementValue[] _items;
125199
readonly bool _isNotNil = true;
126200

src/IKVM.ByteCode/Decoding/ElementValue.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ public readonly ArrayElementValue AsArray()
229229
/// <summary>
230230
/// Encodes this data class to the encoder.
231231
/// </summary>
232-
/// <param name="map"></param>
232+
/// <param name="constantView"></param>
233+
/// <param name="constantPool"></param>
233234
/// <param name="encoder"></param>
234235
public readonly void CopyTo<TConstantView, TConstantPool>(TConstantView constantView, TConstantPool constantPool, ref ElementValueEncoder encoder)
235236
where TConstantView : IConstantView
@@ -286,6 +287,8 @@ public readonly void CopyTo<TConstantView, TConstantPool>(TConstantView constant
286287
encoder.Annotation(e => _annotation.Annotation.CopyTo(constantView, constantPool, ref e));
287288
break;
288289
case ElementValueKind.Array:
290+
var _array = AsArray();
291+
encoder.Array(e => _array.CopyTo(constantView, constantPool, ref e));
289292
break;
290293
}
291294
}

src/IKVM.ByteCode/Encoding/ElementValueEncoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void Class(Utf8ConstantHandle classInfo)
193193
/// <summary>
194194
/// Denotes a "nested" annotation as the value of this element-value pair.
195195
/// </summary>
196-
/// <param name="annotations"></param>
196+
/// <param name="annotationValue"></param>
197197
public void Annotation(Action<AnnotationEncoder> annotationValue)
198198
{
199199
if (_count > 0)

src/IKVM.ByteCode/Encoding/ElementValueTableEncoder.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32

43
using IKVM.ByteCode.Buffers;
54

@@ -150,6 +149,15 @@ public ElementValueTableEncoder Annotation(Action<AnnotationEncoder> annotationV
150149
return ElementValue(e => e.Annotation(annotationValue));
151150
}
152151

152+
/// <summary>
153+
/// Denotes a "nested" annotation as the value of this element-value pair.
154+
/// </summary>
155+
/// <param name="array"></param>
156+
public ElementValueTableEncoder Array(Action<ElementValueTableEncoder> array)
157+
{
158+
return ElementValue(e => e.Array(array));
159+
}
160+
153161
}
154162

155163
}

0 commit comments

Comments
 (0)