Browse Source

Transform RequiresLocationAttribute to 'ref readonly' on function pointers.

pull/3239/head
Siegfried Pammer 10 months ago
parent
commit
783c934bfd
  1. 2
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 9
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs
  3. 11
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FunctionPointers.cs
  4. 15
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs
  5. 15
      ICSharpCode.Decompiler/TypeSystem/FunctionPointerType.cs

2
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -153,7 +153,7 @@
<None Include="TestCases\Pretty\Records.cs" /> <None Include="TestCases\Pretty\Records.cs" />
<Compile Include="TestCases\VBPretty\Issue2192.cs" /> <Compile Include="TestCases\VBPretty\Issue2192.cs" />
<Compile Include="Util\FileUtilityTests.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\CS9_ExtensionGetEnumerator.cs" />
<None Include="TestCases\Pretty\UsingVariables.cs" /> <None Include="TestCases\Pretty\UsingVariables.cs" />
<None Include="TestCases\Pretty\AsyncForeach.cs" /> <None Include="TestCases\Pretty\AsyncForeach.cs" />

9
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs

@ -1,4 +1,7 @@
using System; using System;
#if CS120
using System.Collections.Generic;
#endif
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
@ -74,6 +77,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
#endif #endif
#if CS120
private static void CallWithRefReadonly(ref readonly Dictionary<object, dynamic> d)
{
}
#endif
private static void CallWithRef(ref dynamic d) private static void CallWithRef(ref dynamic d)
{ {
} }

11
ICSharpCode.Decompiler.Tests/TestCases/Pretty/FunctionPointers.cs

@ -95,14 +95,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe delegate*<object, ref readonly dynamic> F12; public unsafe delegate*<object, ref readonly dynamic> F12;
public unsafe delegate*<in dynamic, object> F13; public unsafe delegate*<in dynamic, object> F13;
public unsafe delegate*<out dynamic, object> F14; public unsafe delegate*<out dynamic, object> F14;
public unsafe D<delegate*<dynamic>[], dynamic> F15; #if CS120
public unsafe delegate*<A<object>.B<dynamic>> F16; 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 internal class FunctionPointersWithNativeIntegerTypes
{ {
public unsafe delegate*<nint, nint, nint> F1; public unsafe delegate*<nint, nint, nint> F1;
#if !(CS110 && NET70) #if !(CS110 && NET70)
public unsafe delegate*<IntPtr, IntPtr, nint> F2; public unsafe delegate*<IntPtr, IntPtr, nint> F2;
public unsafe delegate*<nint, IntPtr, IntPtr> F3; public unsafe delegate*<nint, IntPtr, IntPtr> F3;
public unsafe delegate*<IntPtr, nint, IntPtr> F4; public unsafe delegate*<IntPtr, nint, IntPtr> F4;
@ -111,7 +114,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
public unsafe delegate*<delegate*<IntPtr, IntPtr, nint>, IntPtr> F7; public unsafe delegate*<delegate*<IntPtr, IntPtr, nint>, IntPtr> F7;
public unsafe delegate*<IntPtr, delegate*<IntPtr, nint, IntPtr>> F8; public unsafe delegate*<IntPtr, delegate*<IntPtr, nint, IntPtr>> F8;
public unsafe delegate*<IntPtr, delegate*<IntPtr, IntPtr, IntPtr>> F9; public unsafe delegate*<IntPtr, delegate*<IntPtr, IntPtr, IntPtr>> F9;
#endif #endif
} }
internal class FunctionPointersWithRefParams internal class FunctionPointersWithRefParams

15
ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs

@ -326,17 +326,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
return ref x; return ref x;
} }
public ref readonly int M2(ref readonly int x) public ref readonly int M2(ref readonly int x)
{ {
return ref x; return ref x;
} }
public void Test() public void Test()
{ {
int x = 32; int x = 32;
M(in x); M(in x);
M2(in x); M2(in x);
} }
#endif #endif
} }
} }

15
ICSharpCode.Decompiler/TypeSystem/FunctionPointerType.cs

@ -58,17 +58,22 @@ namespace ICSharpCode.Decompiler.TypeSystem
{ {
IType paramType = p; IType paramType = p;
ReferenceKind kind = ReferenceKind.None; 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; 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; 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) if (paramType.Kind == TypeKind.ByReference)

Loading…
Cancel
Save