Skip to content

Commit

Permalink
Fix up some more encodings.
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed Aug 1, 2024
1 parent b61428d commit f0780d8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace IKVM.ByteCode.Parsing
{

public readonly record struct LocalVariableTargetTableItemRecord(ushort Offset, ushort Length, ushort Index)
public readonly record struct LocalVariableTargetTableItemRecord(ushort Start, ushort Length, ushort Index)
{

public static bool TryRead(ref ClassFormatReader reader, out LocalVariableTargetTableItemRecord record)
{
record = default;

if (reader.TryReadU2(out ushort offset) == false)
if (reader.TryReadU2(out ushort start) == false)
return false;

if (reader.TryReadU2(out ushort length) == false)
Expand All @@ -17,7 +17,7 @@ record = default;
if (reader.TryReadU2(out ushort index) == false)
return false;

record = new LocalVariableTargetTableItemRecord(offset, length, index);
record = new LocalVariableTargetTableItemRecord(start, length, index);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace IKVM.ByteCode.Reading
public sealed class BootstrapMethodsAttributeMethodReader : ReaderBase<BootstrapMethodsAttributeMethodRecord>
{

MethodHandleConstantReader methodref;
MethodHandleConstantReader method;
IReadOnlyList<IConstantReader> arguments;

/// <summary>
Expand All @@ -27,7 +27,7 @@ internal BootstrapMethodsAttributeMethodReader(ClassReader declaringClass, Boots
/// <summary>
/// Gets the method being referenced.
/// </summary>
public MethodHandleConstantReader Method => LazyGet(ref methodref, () => DeclaringClass.Constants.Get<MethodrefConstantReader>(Record.MethodRef));
public MethodHandleConstantReader Method => LazyGet(ref method, () => DeclaringClass.Constants.Get<MethodHandleConstantReader>(Record.Method));

/// <summary>
/// Gets the arguments bound to the method reference.
Expand Down
2 changes: 1 addition & 1 deletion src/IKVM.ByteCode/Reading/ConstantValueAttributeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal ConstantValueAttributeReader(ClassReader declaringClass, AttributeInfoR

public object Value => value ??= ResolveValue();

object ResolveValue() => DeclaringClass.Constants.Get<IConstantReader>(Record.Handle) switch
object ResolveValue() => DeclaringClass.Constants.Get<IConstantReader>(Record.Value) switch
{
LongConstantReader l => l.Value,
FloatConstantReader f => f.Value,
Expand Down
20 changes: 19 additions & 1 deletion src/IKVM.ByteCode/Writing/LocalVariableTargetTableEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ public LocalVariableTargetTableEncoder(BlobBuilder builder)
_count = 0;
}

/// <summary>
/// Encodes an existing local variable target table record.
/// </summary>
/// <param name="table"></param>
public void Encode(LocalVariableTargetTableRecord table)
{
foreach (var i in table.Items)
Encode(i);
}

/// <summary>
/// Encodes an existing local variable target.
/// </summary>
/// <param name="target"></param>
public void Encode(LocalVariableTargetTableItemRecord target)
{
LocalVar(target.Start, target.Length, target.Index);
}

/// <summary>
/// Adds a new local variable.
/// </summary>
Expand All @@ -36,7 +55,6 @@ public LocalVariableTargetTableEncoder LocalVar(ushort start, ushort length, ush
new ClassFormatWriter(_countBlob.GetBytes()).TryWriteU2(++_count);
return this;
}

}

}
4 changes: 2 additions & 2 deletions src/IKVM.ByteCode/Writing/TypeAnnotationEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void Encode(TypeAnnotationRecord record)
ThrowsTarget(record.TargetType, target.ThrowsTypeIndex, e => e.Encode(record.TargetPath), record.Type, e => e.Encode(record.Elements));
break;
case LocalVariableTargetTableRecord target:
LocalVarTarget(record.TargetType, e => e.Encode(target), record.Type, e => e.Encode(record.Elements));
LocalVarTarget(record.TargetType, e => e.Encode(target), e => e.Encode(record.TargetPath), record.Type, e => e.Encode(record.Elements));
break;
case CatchTargetRecord target:
CatchTarget(record.TargetType, target.ExceptionTableIndex, e => e.Encode(record.TargetPath), record.Type, e => e.Encode(record.Elements));
Expand Down Expand Up @@ -133,7 +133,7 @@ public void MethodTypeParameter(byte typeParameterIndex, Action<TypePathEncoder>
/// <param name="targetPath"></param>
/// <param name="type"></param>
/// <param name="elementValues"></param>
void SuperTypeTarget(TypeAnnotationTargetType targetType, byte superTypeIndex, Action<TypePathEncoder> targetPath, Utf8ConstantHandle type, Action<ElementValuePairTableEncoder> elementValues)
void SuperTypeTarget(TypeAnnotationTargetType targetType, ushort superTypeIndex, Action<TypePathEncoder> targetPath, Utf8ConstantHandle type, Action<ElementValuePairTableEncoder> elementValues)
{
if (_count > 0)
throw new InvalidOperationException("Encoder can only encode a single type annotation.");
Expand Down

0 comments on commit f0780d8

Please sign in to comment.