Skip to content

Commit

Permalink
Transform RequiresLocationAttribute to 'ref readonly' on function poi…
Browse files Browse the repository at this point in the history
…nters.
  • Loading branch information
siegfriedpammer authored and matt committed Jul 30, 2024
1 parent 9fb1bda commit 39535f1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<None Include="TestCases\Pretty\Records.cs" />
<Compile Include="TestCases\VBPretty\Issue2192.cs" />
<Compile Include="Util\FileUtilityTests.cs" />
<None Include="TestCases\Pretty\FunctionPointers.cs" />
<Compile Include="TestCases\Pretty\FunctionPointers.cs" />
<None Include="TestCases\Pretty\CS9_ExtensionGetEnumerator.cs" />
<None Include="TestCases\Pretty\UsingVariables.cs" />
<None Include="TestCases\Pretty\AsyncForeach.cs" />
Expand Down
9 changes: 9 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
#if CS120
using System.Collections.Generic;
#endif

namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
Expand Down Expand Up @@ -74,6 +77,12 @@ private static void CallWithIn(in dynamic d)
}
#endif

#if CS120
private static void CallWithRefReadonly(ref readonly Dictionary<object, dynamic> d)
{
}
#endif

private static void CallWithRef(ref dynamic d)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ public class B<U>
public unsafe delegate*<object, ref readonly dynamic> F12;
public unsafe delegate*<in dynamic, object> F13;
public unsafe delegate*<out dynamic, object> F14;
public unsafe D<delegate*<dynamic>[], dynamic> F15;
public unsafe delegate*<A<object>.B<dynamic>> F16;
#if CS120
public unsafe delegate*<ref readonly dynamic, object> F15;
#endif
public unsafe D<delegate*<dynamic>[], dynamic> F16;
public unsafe delegate*<A<object>.B<dynamic>> F17;
}

internal class FunctionPointersWithNativeIntegerTypes
{
public unsafe delegate*<nint, nint, nint> F1;
#if !(CS110 && NET70)
#if !(CS110 && NET70)
public unsafe delegate*<IntPtr, IntPtr, nint> F2;
public unsafe delegate*<nint, IntPtr, IntPtr> F3;
public unsafe delegate*<IntPtr, nint, IntPtr> F4;
Expand All @@ -111,7 +114,7 @@ internal class FunctionPointersWithNativeIntegerTypes
public unsafe delegate*<delegate*<IntPtr, IntPtr, nint>, IntPtr> F7;
public unsafe delegate*<IntPtr, delegate*<IntPtr, nint, IntPtr>> F8;
public unsafe delegate*<IntPtr, delegate*<IntPtr, IntPtr, IntPtr>> F9;
#endif
#endif
}

internal class FunctionPointersWithRefParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,18 @@ public ref readonly int M(in int x)
{
return ref x;
}

public ref readonly int M2(ref readonly int x)
{
return ref x;
}

public void Test()
{
int x = 32;
M(in x);
M2(in x);
}
public void Test()
{
int x = 32;
M(in x);
M2(in x);
}
#endif
}
}
}
15 changes: 10 additions & 5 deletions ICSharpCode.Decompiler/TypeSystem/FunctionPointerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,22 @@ public static FunctionPointerType FromSignature(MethodSignature<IType> signature
{
IType paramType = p;
ReferenceKind kind = ReferenceKind.None;
if (p is ModifiedType modreq)
if (p is ModifiedType mod)
{
if (modreq.Modifier.IsKnownType(KnownAttribute.In))
if (mod.Modifier.IsKnownType(KnownAttribute.In))
{
kind = ReferenceKind.In;
paramType = modreq.ElementType;
paramType = mod.ElementType;
}
else if (modreq.Modifier.IsKnownType(KnownAttribute.Out))
else if (mod.Modifier.IsKnownType(KnownAttribute.Out))
{
kind = ReferenceKind.Out;
paramType = modreq.ElementType;
paramType = mod.ElementType;
}
else if (mod.Modifier.IsKnownType(KnownAttribute.RequiresLocation))
{
kind = ReferenceKind.RefReadOnly;
paramType = mod.ElementType;
}
}
if (paramType.Kind == TypeKind.ByReference)
Expand Down

0 comments on commit 39535f1

Please sign in to comment.