Skip to content

Commit

Permalink
Fix disassembling TypeSpec when it appears in array type
Browse files Browse the repository at this point in the history
Issue: #147
  • Loading branch information
MSDN-WhiteKnight committed Mar 10, 2024
1 parent 4b59136 commit ad90b7c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ public IEnumerable<SyntaxNode> GetTypeSyntax(Type t)

if (et != null)
{
IEnumerable<SyntaxNode> nodes = this.GetTypeSyntax(et);
IEnumerable<SyntaxNode> nodes;

if (et is TypeSpec) nodes = this.GetTypeNameSyntax(et);
else nodes = this.GetTypeSyntax(et);

foreach (SyntaxNode x in nodes) yield return x;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Compile Include="Syntax\DisassemblerTests.cs" />
<Compile Include="Syntax\IdentifierSyntaxTest.cs" />
<Compile Include="Syntax\SyntaxFactoryTests.cs" />
<Compile Include="Syntax\SyntaxGenerationTests.cs" />
<Compile Include="Syntax\SyntaxNodeTests.cs" />
<Compile Include="Syntax\SyntaxReaderTests.cs" />
<Compile Include="Syntax\TokenReaderTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* CIL Tools
* Copyright (c) 2024, MSDN.WhiteKnight (https://github.com/MSDN-WhiteKnight)
* License: BSD 2.0 */
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CilTools.Tests.Common;
using CilTools.Tests.Common.TextUtils;

namespace CilTools.BytecodeAnalysis.Tests.Syntax
{
[TestClass]
public class SyntaxGenerationTests
{
// Tests that verify disassembler output in different cases

[TestMethod]
[MethodTestData(typeof(SampleMethods), "TestArrayOfArrays", BytecodeProviders.Metadata)]
public void Test_Operand_ArrayOfArrays(MethodBase mi)
{
CilGraph graph = CilGraph.Create(mi);
string str = graph.ToText();

AssertThat.IsMatch(str, new Text[] {
Text.Any, "newarr", Text.Any, "uint8[]", Text.Any
});
}
}
}
5 changes: 5 additions & 0 deletions tests/CilTools.Tests.Common/TestData/SampleMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public static void TestNestedTypes(Environment.SpecialFolder sf) { }

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TestAggressiveInlining() { }

public static byte[][] TestArrayOfArrays()
{
return new byte[0][];
}
}

public class MyPoint
Expand Down

0 comments on commit ad90b7c

Please sign in to comment.