Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,7 @@ public void AddCatchRegion(System.Reflection.Metadata.Ecma335.LabelHandle trySta
public void AddFaultRegion(System.Reflection.Metadata.Ecma335.LabelHandle tryStart, System.Reflection.Metadata.Ecma335.LabelHandle tryEnd, System.Reflection.Metadata.Ecma335.LabelHandle handlerStart, System.Reflection.Metadata.Ecma335.LabelHandle handlerEnd) { }
public void AddFilterRegion(System.Reflection.Metadata.Ecma335.LabelHandle tryStart, System.Reflection.Metadata.Ecma335.LabelHandle tryEnd, System.Reflection.Metadata.Ecma335.LabelHandle handlerStart, System.Reflection.Metadata.Ecma335.LabelHandle handlerEnd, System.Reflection.Metadata.Ecma335.LabelHandle filterStart) { }
public void AddFinallyRegion(System.Reflection.Metadata.Ecma335.LabelHandle tryStart, System.Reflection.Metadata.Ecma335.LabelHandle tryEnd, System.Reflection.Metadata.Ecma335.LabelHandle handlerStart, System.Reflection.Metadata.Ecma335.LabelHandle handlerEnd) { }
public void Clear() { }
}
public readonly partial struct CustomAttributeArrayTypeEncoder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public ControlFlowBuilder()
_labels = ImmutableArray.CreateBuilder<int>();
}

internal void Clear()
/// <summary>
/// Clears the object's internal state, allowing the same instance to be reused.
/// </summary>
public void Clear()
{
_branches.Clear();
_labels.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,44 @@ public void Branch_LongInstruction_LongDistance()
(byte)ILOpCode.Ret
}, builder.ToArray());
}

[Fact]
public void Clear()
{
var cfb = new ControlFlowBuilder();

var il1 = GenerateSampleIL(cfb);
cfb.Clear();
var il2 = GenerateSampleIL(cfb);

AssertEx.Equal(il1, il2);

static byte[] GenerateSampleIL(ControlFlowBuilder cfb)
{
var code = new BlobBuilder();
var il = new InstructionEncoder(code, cfb);

var l1 = il.DefineLabel();
var l2 = il.DefineLabel();
var l3 = il.DefineLabel();
var l4 = il.DefineLabel();

il.MarkLabel(l1);
il.OpCode(ILOpCode.Nop);
il.Branch(ILOpCode.Br_s, l1);
il.MarkLabel(l2);
il.OpCode(ILOpCode.Nop);
il.MarkLabel(l3);
il.OpCode(ILOpCode.Nop);
il.MarkLabel(l4);

cfb.AddCatchRegion(l1, l2, l3, l4, MetadataTokens.TypeDefinitionHandle(1));

var builder = new BlobBuilder();
new MethodBodyStreamEncoder(builder).AddMethodBody(il);

return builder.ToArray();
}
}
}
}