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. 7
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FunctionPointers.cs
  4. 1
      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 @@ @@ -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" />

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

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

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

@ -95,8 +95,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -95,8 +95,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
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

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

@ -326,6 +326,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -326,6 +326,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
return ref x;
}
public ref readonly int M2(ref readonly int x)
{
return ref x;

15
ICSharpCode.Decompiler/TypeSystem/FunctionPointerType.cs

@ -58,17 +58,22 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -58,17 +58,22 @@ namespace ICSharpCode.Decompiler.TypeSystem
{
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)

Loading…
Cancel
Save