Skip to content

Commit 07d0244

Browse files
authored
Merge pull request #618 from Washi1337/development
6.0.0-beta.3
2 parents 70794cd + 5121c1a commit 07d0244

38 files changed

Lines changed: 469 additions & 181 deletions

File tree

.github/actions/get-dotnet-path/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ runs:
3333
run: |
3434
if ('${{runner.os == 'Windows'}}' -eq 'true') {
3535
if ('${{inputs.architecture == 'x86'}}' -eq 'true') {
36-
$dotnet = "${{steps.get-program-files-x86.outputs.path}}/dotnet/dotnet.exe";
36+
$dotnet = "${{steps.get-program-files-x86.outputs.path}}\dotnet\dotnet.exe";
3737
} else {
38-
$dotnet = "${{steps.get-program-files-x64.outputs.path}}/dotnet/dotnet.exe";
38+
$dotnet = "${{steps.get-program-files-x64.outputs.path}}\dotnet\dotnet.exe";
3939
}
4040
} elseif ('${{inputs.image == 'macos-14'}}' -eq 'true') {
4141
if ('${{inputs.architecture == 'x64'}}' -eq 'true') {

.github/actions/setup-dotnet-windows/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ runs:
4242

4343
- name: Setup .NET ${{inputs.architecture}} ${{steps.get_channels.outputs.channels_multiline}}
4444
uses: actions/setup-dotnet@v4
45+
if: ${{inputs.architecture != 'x86'}}
4546
with:
4647
dotnet-version: |
4748
${{steps.get_channels.outputs.channel}}

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ updates:
1010
directory: "/" # Location of package manifests
1111
schedule:
1212
interval: "daily"
13+
groups:
14+
ms-dependencies:
15+
patterns:
16+
- "System*"
17+
- "Microsoft*"
18+
- "xunit*"
1319

1420
- package-ecosystem: "github-actions"
1521
target-branch: "development"

.github/workflows/test-and-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ jobs:
106106
architecture: ${{matrix.runner.arch}}
107107
dotnet_target_frameworks: ${{needs.variables.outputs.DOTNET_TARGET_FRAMEWORKS}}
108108
build_configuration: ${{matrix.build_configuration}}
109-
# Ignore MacOS test results since support is yet lacking
110-
is_experimental: ${{matrix.runner.image != 'windows-2022' && matrix.runner.image != 'ubuntu-22.04'}}
109+
# TODO: Fully support tests on non-x64 and MacOS.
110+
is_experimental: ${{matrix.runner.arch != 'x64' || (matrix.runner.image != 'windows-2022' && matrix.runner.image != 'ubuntu-22.04')}}
111111
skip_experimental: ${{ needs.variables.outputs.EXPERIMENTAL != 'true' }}
112112

113113
publish:

AsmResolver.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ EndProject
2626
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestBinaries", "TestBinaries", "{7919C544-023E-4617-A41C-27A69DB397DE}"
2727
EndProject
2828
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNet", "DotNet", "{B3AF102B-ABE1-41B2-AE48-C40702F45AB0}"
29+
ProjectSection(SolutionItems) = preProject
30+
test\TestBinaries\DotNet\Directory.Build.props = test\TestBinaries\DotNet\Directory.Build.props
31+
EndProjectSection
2932
EndProject
3033
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorld", "test\TestBinaries\DotNet\HelloWorld\HelloWorld.csproj", "{856EEF27-8430-4360-9E4C-F923AF142D23}"
3134
EndProject

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<PublishRepositoryUrl>true</PublishRepositoryUrl>
77
<EmbedUntrackedSources>true</EmbedUntrackedSources>
88
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
9-
<LangVersion>10</LangVersion>
9+
<LangVersion>12</LangVersion>
1010
<VersionPrefix>6.0.0</VersionPrefix>
11-
<VersionSuffix>beta.2</VersionSuffix>
11+
<VersionSuffix>beta.3</VersionSuffix>
1212
<Deterministic>true</Deterministic>
1313
<UseArtifactsOutput>true</UseArtifactsOutput>
1414
</PropertyGroup>

src/AsmResolver.DotNet.Dynamic/DynamicTypeSignatureReader.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
#if !NET8_0_OR_GREATER
23
using System.Diagnostics.CodeAnalysis;
34
using System.Reflection;
5+
#endif
46
using AsmResolver.DotNet.Signatures;
57

68
namespace AsmResolver.DotNet.Dynamic
@@ -12,18 +14,15 @@ namespace AsmResolver.DotNet.Dynamic
1214
/// </summary>
1315
public class DynamicTypeSignatureResolver : PhysicalTypeSignatureResolver
1416
{
15-
private static readonly MethodInfo? GetTypeFromHandleUnsafeMethod;
16-
17-
static DynamicTypeSignatureResolver()
18-
{
19-
// We need to use reflection for this to stay compatible with .netstandard 2.0.
20-
GetTypeFromHandleUnsafeMethod = typeof(Type)
17+
#if !NET8_0_OR_GREATER
18+
// We need to use reflection for this to stay compatible with .netstandard 2.0.
19+
private static readonly MethodInfo? GetTypeFromHandleUnsafeMethod = typeof(Type)
2120
.GetMethod("GetTypeFromHandleUnsafe",
2221
(BindingFlags) (-1),
2322
null,
2423
new[] {typeof(IntPtr)},
2524
null);
26-
}
25+
#endif
2726

2827
/// <summary>
2928
/// Gets the singleton instance of the <see cref="DynamicTypeSignatureResolver"/> class.
@@ -36,17 +35,25 @@ static DynamicTypeSignatureResolver()
3635
/// <summary>
3736
/// Gets a value indicating whether dynamic resolution of method tables is supported.
3837
/// </summary>
38+
#if NET8_0_OR_GREATER
39+
public static bool IsSupported => true;
40+
#else
3941
[MemberNotNullWhen(true, nameof(GetTypeFromHandleUnsafeMethod))]
4042
public static bool IsSupported => GetTypeFromHandleUnsafeMethod is not null;
43+
#endif
4144

4245
/// <inheritdoc />
4346
public override TypeSignature ResolveRuntimeType(ref BlobReaderContext context, nint address)
4447
{
48+
#if NET8_0_OR_GREATER
49+
var clrType = Type.GetTypeFromHandle(RuntimeTypeHandle.FromIntPtr(address));
50+
#else
4551
if (!IsSupported)
4652
throw new PlatformNotSupportedException("The current platform does not support the translation of raw type handles to System.Type instances.");
4753

4854
// Let the runtime translate the address to a type and import it.
4955
var clrType = (Type?) GetTypeFromHandleUnsafeMethod.Invoke(null, new object[] { address });
56+
#endif
5057

5158
var type = clrType is not null
5259
? new ReferenceImporter(context.ReaderContext.ParentModule).ImportType(clrType)

src/AsmResolver.DotNet/Code/Cil/CilInstructionCollection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace AsmResolver.DotNet.Code.Cil
1212
/// Represents a collection of CIL instructions found in a method body.
1313
/// </summary>
1414
[DebuggerDisplay("Count = {" + nameof(Count) + "}")]
15-
public partial class CilInstructionCollection : IList<CilInstruction>
15+
public partial class CilInstructionCollection : IList<CilInstruction>, IReadOnlyList<CilInstruction>
1616
{
1717
private readonly List<CilInstruction> _items = new();
1818
private ICilLabel? _endLabel;
@@ -34,7 +34,7 @@ public CilMethodBody Owner
3434
get;
3535
}
3636

37-
/// <inheritdoc />
37+
/// <inheritdoc cref="ICollection{T}.Count" />
3838
public int Count => _items.Count;
3939

4040
/// <inheritdoc />
@@ -45,7 +45,7 @@ public CilMethodBody Owner
4545
/// </summary>
4646
public int Size => _items.Sum(x => x.Size);
4747

48-
/// <inheritdoc />
48+
/// <inheritdoc cref="IList{T}.this" />
4949
public CilInstruction this[int index]
5050
{
5151
get => _items[index];
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace AsmResolver.DotNet.Signatures.Parsing;
6+
7+
internal sealed class ParsedTypeFullName(TypeName name)
8+
{
9+
public TypeName Name { get; } = name;
10+
11+
public IList<TypeAnnotation> Annotations { get; } = new List<TypeAnnotation>();
12+
13+
public IResolutionScope? Scope { get; set; }
14+
15+
public TypeSignature ToTypeSignature(ModuleDefinition contextModule)
16+
{
17+
var baseTypeDefOrRef = Name.ToTypeDefOrRef(contextModule, Scope);
18+
19+
// The first annotation may be a generic instantiation, of which the root typesig is represented by
20+
// GenericInstanceTypeSignature.
21+
int startIndex = 0;
22+
TypeSignature signature;
23+
if (Annotations.Count > 0 && Annotations[0] is {Kind: TypeAnnotationType.GenericInstance} first)
24+
{
25+
var arguments = new TypeSignature[first.TypeArguments.Count];
26+
for (int i = 0; i < first.TypeArguments.Count; i++)
27+
arguments[i] = first.TypeArguments[i].ToTypeSignature(contextModule);
28+
29+
signature = baseTypeDefOrRef.MakeGenericInstanceType(arguments);
30+
startIndex++;
31+
}
32+
else
33+
{
34+
signature = baseTypeDefOrRef.ToTypeSignature();
35+
}
36+
37+
// Go over all type annotations and annotate the type signature accordingly.
38+
for (int i = startIndex; i < Annotations.Count; i++)
39+
{
40+
signature = Annotations[i].Kind switch
41+
{
42+
TypeAnnotationType.ByReference => signature.MakeByReferenceType(),
43+
TypeAnnotationType.Pointer => signature.MakePointerType(),
44+
TypeAnnotationType.SzArray => signature.MakeSzArrayType(),
45+
TypeAnnotationType.Array => signature.MakeArrayType(Annotations[i].Dimensions.ToArray()),
46+
TypeAnnotationType.GenericInstance => throw new FormatException("Cannot instantiate a non-generic type."),
47+
_ => throw new ArgumentOutOfRangeException()
48+
};
49+
}
50+
51+
return signature;
52+
}
53+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
3+
namespace AsmResolver.DotNet.Signatures.Parsing;
4+
5+
internal readonly struct TypeAnnotation
6+
{
7+
private readonly object? _data;
8+
9+
public TypeAnnotation(TypeAnnotationType kind)
10+
{
11+
Kind = kind;
12+
_data = null;
13+
}
14+
15+
public TypeAnnotation(IList<ArrayDimension> dimensions)
16+
{
17+
Kind = TypeAnnotationType.Array;
18+
_data = dimensions;
19+
}
20+
21+
public TypeAnnotation(IList<ParsedTypeFullName> typeArguments)
22+
{
23+
Kind = TypeAnnotationType.GenericInstance;
24+
_data = typeArguments;
25+
}
26+
27+
public TypeAnnotationType Kind { get; }
28+
29+
public IList<ArrayDimension> Dimensions => (IList<ArrayDimension>) _data!;
30+
31+
public IList<ParsedTypeFullName> TypeArguments => (IList<ParsedTypeFullName>) _data!;
32+
}

0 commit comments

Comments
 (0)