|
3 | 3 | using System.Collections; |
4 | 4 | using System.Collections.Generic; |
5 | 5 |
|
| 6 | +using IKVM.ByteCode.Encoding; |
| 7 | + |
6 | 8 | namespace IKVM.ByteCode.Decoding |
7 | 9 | { |
8 | 10 |
|
@@ -121,6 +123,78 @@ public static bool TryRead(ref ClassFormatReader reader, out ArrayElementValue v |
121 | 123 | return true; |
122 | 124 | } |
123 | 125 |
|
| 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 | + |
124 | 198 | readonly ElementValue[] _items; |
125 | 199 | readonly bool _isNotNil = true; |
126 | 200 |
|
|
0 commit comments