Browse Source

Update tests to latest Roslyn implementation.

pull/1596/head
Siegfried Pammer 6 years ago
parent
commit
9590cfbf59
  1. 8
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 9
      ICSharpCode.Decompiler/IL/ILInstructionExtensions.cs
  3. 46
      ICSharpCode.Decompiler/IL/Instructions/Block.cs
  4. 5
      ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs
  5. 2
      ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj
  6. 8
      ILSpy.BamlDecompiler.Tests/app.config

8
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -42,13 +42,13 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="DiffLib" Version="2017.7.26.1241" /> <PackageReference Include="DiffLib" Version="2017.7.26.1241" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.2" /> <PackageReference Include="Microsoft.Build.Locator" Version="1.2.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0-beta4-final" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.2.0-beta3-final" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.0.0-beta4-final" /> <PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.2.0-beta3-final" />
<PackageReference Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta1-63314-01" /> <PackageReference Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta1-63314-01" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" /> <PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" /> <PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="NUnit" Version="3.11.0" /> <PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="System.Memory" Version="4.5.1" /> <PackageReference Include="System.Memory" Version="4.5.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

9
ICSharpCode.Decompiler/IL/ILInstructionExtensions.cs

@ -18,5 +18,14 @@ namespace ICSharpCode.Decompiler.IL
target.AddILRange(range); target.AddILRange(range);
return target; return target;
} }
public static ILInstruction GetNextSibling(this ILInstruction instruction)
{
if (instruction?.Parent == null)
return null;
if (instruction.ChildIndex + 1 >= instruction.Parent.Children.Count)
return null;
return instruction.Parent.Children[instruction.ChildIndex + 1];
}
} }
} }

46
ICSharpCode.Decompiler/IL/Instructions/Block.cs

@ -43,11 +43,11 @@ namespace ICSharpCode.Decompiler.IL
{ {
public static readonly SlotInfo InstructionSlot = new SlotInfo("Instruction", isCollection: true); public static readonly SlotInfo InstructionSlot = new SlotInfo("Instruction", isCollection: true);
public static readonly SlotInfo FinalInstructionSlot = new SlotInfo("FinalInstruction"); public static readonly SlotInfo FinalInstructionSlot = new SlotInfo("FinalInstruction");
public readonly BlockKind Kind; public readonly BlockKind Kind;
public readonly InstructionCollection<ILInstruction> Instructions; public readonly InstructionCollection<ILInstruction> Instructions;
ILInstruction finalInstruction; ILInstruction finalInstruction;
/// <summary> /// <summary>
/// For blocks in a block container, this field holds /// For blocks in a block container, this field holds
/// the number of incoming control flow edges to this block. /// the number of incoming control flow edges to this block.
@ -77,21 +77,21 @@ namespace ICSharpCode.Decompiler.IL
SetChildInstruction(ref finalInstruction, value, Instructions.Count); SetChildInstruction(ref finalInstruction, value, Instructions.Count);
} }
} }
protected internal override void InstructionCollectionUpdateComplete() protected internal override void InstructionCollectionUpdateComplete()
{ {
base.InstructionCollectionUpdateComplete(); base.InstructionCollectionUpdateComplete();
if (finalInstruction.Parent == this) if (finalInstruction.Parent == this)
finalInstruction.ChildIndex = Instructions.Count; finalInstruction.ChildIndex = Instructions.Count;
} }
public Block(BlockKind kind = BlockKind.ControlFlow) : base(OpCode.Block) public Block(BlockKind kind = BlockKind.ControlFlow) : base(OpCode.Block)
{ {
this.Kind = kind; this.Kind = kind;
this.Instructions = new InstructionCollection<ILInstruction>(this, 0); this.Instructions = new InstructionCollection<ILInstruction>(this, 0);
this.FinalInstruction = new Nop(); this.FinalInstruction = new Nop();
} }
public override ILInstruction Clone() public override ILInstruction Clone()
{ {
Block clone = new Block(Kind); Block clone = new Block(Kind);
@ -100,7 +100,7 @@ namespace ICSharpCode.Decompiler.IL
clone.FinalInstruction = this.FinalInstruction.Clone(); clone.FinalInstruction = this.FinalInstruction.Clone();
return clone; return clone;
} }
internal override void CheckInvariant(ILPhase phase) internal override void CheckInvariant(ILPhase phase)
{ {
base.CheckInvariant(phase); base.CheckInvariant(phase);
@ -133,18 +133,17 @@ namespace ICSharpCode.Decompiler.IL
break; break;
} }
} }
public override StackType ResultType { public override StackType ResultType {
get { get {
return finalInstruction.ResultType; return finalInstruction.ResultType;
} }
} }
/// <summary> /// <summary>
/// Gets the name of this block. /// Gets the name of this block.
/// </summary> /// </summary>
public string Label public string Label {
{
get { return Disassembler.DisassemblerHelpers.OffsetToString(this.StartILOffset); } get { return Disassembler.DisassemblerHelpers.OffsetToString(this.StartILOffset); }
} }
@ -179,19 +178,19 @@ namespace ICSharpCode.Decompiler.IL
output.Write("}"); output.Write("}");
output.MarkFoldEnd(); output.MarkFoldEnd();
} }
protected override int GetChildCount() protected override int GetChildCount()
{ {
return Instructions.Count + 1; return Instructions.Count + 1;
} }
protected override ILInstruction GetChild(int index) protected override ILInstruction GetChild(int index)
{ {
if (index == Instructions.Count) if (index == Instructions.Count)
return finalInstruction; return finalInstruction;
return Instructions[index]; return Instructions[index];
} }
protected override void SetChild(int index, ILInstruction value) protected override void SetChild(int index, ILInstruction value)
{ {
if (index == Instructions.Count) if (index == Instructions.Count)
@ -199,7 +198,7 @@ namespace ICSharpCode.Decompiler.IL
else else
Instructions[index] = value; Instructions[index] = value;
} }
protected override SlotInfo GetChildSlot(int index) protected override SlotInfo GetChildSlot(int index)
{ {
if (index == Instructions.Count) if (index == Instructions.Count)
@ -207,7 +206,7 @@ namespace ICSharpCode.Decompiler.IL
else else
return InstructionSlot; return InstructionSlot;
} }
protected override InstructionFlags ComputeFlags() protected override InstructionFlags ComputeFlags()
{ {
var flags = InstructionFlags.None; var flags = InstructionFlags.None;
@ -217,7 +216,7 @@ namespace ICSharpCode.Decompiler.IL
flags |= FinalInstruction.Flags; flags |= FinalInstruction.Flags;
return flags; return flags;
} }
public override InstructionFlags DirectFlags { public override InstructionFlags DirectFlags {
get { get {
return InstructionFlags.None; return InstructionFlags.None;
@ -280,6 +279,21 @@ namespace ICSharpCode.Decompiler.IL
return inst; return inst;
} }
/// <summary>
/// Gets the closest parent Block.
/// Returns null, if the instruction is not a descendant of a Block.
/// </summary>
public static Block FindClosestBlock(ILInstruction inst)
{
var curr = inst;
while (curr != null) {
if (curr is Block)
return (Block)curr;
curr = curr.Parent;
}
return null;
}
public bool MatchInlineAssignBlock(out CallInstruction call, out ILInstruction value) public bool MatchInlineAssignBlock(out CallInstruction call, out ILInstruction value)
{ {
call = null; call = null;

5
ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

@ -271,6 +271,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
Block block; Block block;
if (TransformSpanTCtorContainingStackAlloc(inst, out ILInstruction locallocSpan)) { if (TransformSpanTCtorContainingStackAlloc(inst, out ILInstruction locallocSpan)) {
context.Step("new Span<T>(stackalloc) -> stackalloc Span<T>", inst);
inst.ReplaceWith(locallocSpan); inst.ReplaceWith(locallocSpan);
block = null; block = null;
ILInstruction stmt = locallocSpan; ILInstruction stmt = locallocSpan;
@ -281,7 +282,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
stmt = stmt.Parent; stmt = stmt.Parent;
} }
//ILInlining.InlineIfPossible(block, stmt.ChildIndex - 1, context); // Special case to eliminate extra store
if (stmt.GetNextSibling() is StLoc)
ILInlining.InlineIfPossible(block, stmt.ChildIndex, context);
return; return;
} }
if (TransformArrayInitializers.TransformSpanTArrayInitialization(inst, context, out block)) { if (TransformArrayInitializers.TransformSpanTArrayInitialization(inst, context, out block)) {

2
ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj

@ -31,7 +31,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="NUnit" Version="3.11.0" /> <PackageReference Include="NUnit" Version="3.12.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

8
ILSpy.BamlDecompiler.Tests/app.config

@ -7,8 +7,14 @@
<bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0"/> <bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0"/>
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1"/>
</dependentAssembly>
</assemblyBinding>
</runtime> </runtime>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup> </startup>
</configuration> </configuration>

Loading…
Cancel
Save