Skip to content

Commit 7182f4b

Browse files
committed
Use MarshalDirection type in generators and update design doc
1 parent a958552 commit 7182f4b

File tree

14 files changed

+30
-72
lines changed

14 files changed

+30
-72
lines changed

docs/design/libraries/ComInterfaceGenerator/VTableStubs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class VirtualMethodIndexAttribute : Attribute
2828

2929
public bool ImplicitThisParameter { get; set; } = true;
3030

31-
public CustomTypeMarshallerDirection Direction { get; set; } = CustomTypeMarshallerDirection.Ref;
31+
public MarshalDirection Direction { get; set; } = MarshalDirection.Bidirectional;
3232

3333
/// <summary>
3434
/// Gets or sets how to marshal string arguments to the method.

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSStubCodeContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal sealed record JSImportCodeContext : JSStubCodeContext
2525
public JSImportCodeContext(JSImportData attributeData, StubCodeContext inner)
2626
{
2727
_inner = inner;
28-
Direction = CustomTypeMarshallingDirection.In;
28+
Direction = MarshalDirection.ManagedToUnmanaged;
2929
AttributeData = attributeData;
3030
}
3131

@@ -37,7 +37,7 @@ internal sealed record JSExportCodeContext : JSStubCodeContext
3737
public JSExportCodeContext(JSExportData attributeData, StubCodeContext inner)
3838
{
3939
_inner = inner;
40-
Direction = CustomTypeMarshallingDirection.Out;
40+
Direction = MarshalDirection.UnmanagedToManaged;
4141
AttributeData = attributeData;
4242
}
4343

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/FuncJSGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
5353
.Select(a => ParseTypeName(a.FullTypeName))
5454
.ToArray();
5555

56-
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.In && info.IsManagedReturnPosition)
56+
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == MarshalDirection.ManagedToUnmanaged && info.IsManagedReturnPosition)
5757
{
5858
yield return ToManagedMethod(target, source, jsty);
5959
}
6060

61-
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == CustomTypeMarshallingDirection.Out && info.IsManagedReturnPosition)
61+
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == MarshalDirection.UnmanagedToManaged && info.IsManagedReturnPosition)
6262
{
6363
yield return ToJSMethod(target, source, jsty);
6464
}
@@ -68,12 +68,12 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
6868
yield return x;
6969
}
7070

71-
if (context.CurrentStage == StubCodeContext.Stage.Invoke && context.Direction == CustomTypeMarshallingDirection.In && !info.IsManagedReturnPosition)
71+
if (context.CurrentStage == StubCodeContext.Stage.Invoke && context.Direction == MarshalDirection.ManagedToUnmanaged && !info.IsManagedReturnPosition)
7272
{
7373
yield return ToJSMethod(target, source, jsty);
7474
}
7575

76-
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.Out && !info.IsManagedReturnPosition)
76+
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == MarshalDirection.UnmanagedToManaged && !info.IsManagedReturnPosition)
7777
{
7878
yield return ToManagedMethod(target, source, jsty);
7979
}

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/PrimitiveJSGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
3232
? Argument(IdentifierName(context.GetIdentifiers(info).native))
3333
: _inner.AsArgument(info, context);
3434

35-
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.In && info.IsManagedReturnPosition)
35+
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == MarshalDirection.ManagedToUnmanaged && info.IsManagedReturnPosition)
3636
{
3737
yield return ToManagedMethod(target, source);
3838
}
3939

40-
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == CustomTypeMarshallingDirection.Out && info.IsManagedReturnPosition)
40+
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == MarshalDirection.UnmanagedToManaged && info.IsManagedReturnPosition)
4141
{
4242
yield return ToJSMethod(target, source);
4343
}
@@ -47,12 +47,12 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
4747
yield return x;
4848
}
4949

50-
if (context.CurrentStage == StubCodeContext.Stage.Invoke && context.Direction == CustomTypeMarshallingDirection.In && !info.IsManagedReturnPosition)
50+
if (context.CurrentStage == StubCodeContext.Stage.Invoke && context.Direction == MarshalDirection.ManagedToUnmanaged && !info.IsManagedReturnPosition)
5151
{
5252
yield return ToJSMethod(target, source);
5353
}
5454

55-
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.Out && !info.IsManagedReturnPosition)
55+
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == MarshalDirection.UnmanagedToManaged && !info.IsManagedReturnPosition)
5656
{
5757
yield return ToManagedMethod(target, source);
5858
}

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/TaskJSGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
4545
? Argument(IdentifierName(context.GetIdentifiers(info).native))
4646
: _inner.AsArgument(info, context);
4747

48-
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.In && info.IsManagedReturnPosition)
48+
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == MarshalDirection.ManagedToUnmanaged && info.IsManagedReturnPosition)
4949
{
5050
yield return jsty.ResultTypeInfo.FullTypeName == "void"
5151
? ToManagedMethodVoid(target, source)
5252
: ToManagedMethod(target, source, jsty.ResultTypeInfo.Syntax);
5353
}
5454

55-
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == CustomTypeMarshallingDirection.Out && info.IsManagedReturnPosition)
55+
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == MarshalDirection.UnmanagedToManaged && info.IsManagedReturnPosition)
5656
{
5757
yield return jsty.ResultTypeInfo.FullTypeName == "void"
5858
? ToJSMethodVoid(target, source)
@@ -64,14 +64,14 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
6464
yield return x;
6565
}
6666

67-
if (context.CurrentStage == StubCodeContext.Stage.Invoke && context.Direction == CustomTypeMarshallingDirection.In && !info.IsManagedReturnPosition)
67+
if (context.CurrentStage == StubCodeContext.Stage.Invoke && context.Direction == MarshalDirection.ManagedToUnmanaged && !info.IsManagedReturnPosition)
6868
{
6969
yield return jsty.ResultTypeInfo.FullTypeName == "void"
7070
? ToJSMethodVoid(target, source)
7171
: ToJSMethod(target, source, jsty.ResultTypeInfo.Syntax);
7272
}
7373

74-
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.Out && !info.IsManagedReturnPosition)
74+
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == MarshalDirection.UnmanagedToManaged && !info.IsManagedReturnPosition)
7575
{
7676
yield return jsty.ResultTypeInfo.FullTypeName == "void"
7777
? ToManagedMethodVoid(target, source)

src/libraries/System.Runtime.InteropServices.JavaScript/tests/JSImportGenerator.UnitTest/JSImportGenerator.Unit.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<Compile Include="$(CommonTestPath)SourceGenerators\LiveReferencePack.cs" Link="Common\SourceGenerators\LiveReferencePack.cs" />
9-
<Compile Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\LibraryImportGenerator.UnitTests\TestUtils.cs" Link="LibraryImportGenerator\TestUtils.cs" />
9+
<Compile Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\Common\TestUtils.cs" Link="System\Runtime\InteropServices\Common\TestUtils.cs" />
1010
<Compile Include="CodeSnippets.cs" />
1111
<Compile Include="Fails.cs" />
1212
<Compile Include="Compiles.cs" />
@@ -16,7 +16,7 @@
1616
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisVersion)" />
1717
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="$(CompilerPlatformTestingVersion)" />
1818
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="$(CompilerPlatformTestingVersion)" />
19-
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\Ancillary.Interop\Ancillary.Interop.csproj" />
19+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\Ancillary.Interop\Ancillary.Interop.csproj" />
2020
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices.JavaScript\gen\JSImportGenerator\JSImportGenerator.csproj" />
2121
<None Include="$(RepoRoot)/NuGet.config" Link="NuGet.config" CopyToOutputDirectory="PreserveNewest" />
2222
</ItemGroup>

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
2929
</ItemGroup>
3030

31-
<ItemGroup>
32-
<Compile Include="../../tests/Ancillary.Interop/MarshalDirection.cs" />
33-
</ItemGroup>
34-
3531
<ItemGroup>
3632
<None Include="$(TargetPath)" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
3733
<None Include="$(AssemblyName).props" Pack="true" PackagePath="build" />

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodIndexData.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
5-
using System.Runtime.InteropServices;
6-
using System.Runtime.InteropServices.Marshalling;
7-
using Microsoft.CodeAnalysis;
8-
94
namespace Microsoft.Interop
105
{
116
/// <summary>

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Diagnostics;
88
using System.Linq;
99
using System.Runtime.InteropServices;
10-
using System.Runtime.InteropServices.Marshalling;
1110
using System.Text;
1211
using System.Threading;
1312
using Microsoft.CodeAnalysis;

src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/CustomTypeMarshallingDirection.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Microsoft.Interop.SourceGeneration.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<Compile Include="$(CoreLibSharedDir)\System\Runtime\InteropServices\Marshalling\MarshalMode.cs" Link="Production\MarshalMode.cs" />
1414
</ItemGroup>
1515

16+
<ItemGroup>
17+
<Compile Include="../../tests/Common/MarshalDirection.cs" />
18+
</ItemGroup>
19+
1620
<ItemGroup>
1721
<PackageReference Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion_4_4)" PrivateAssets="all" />
1822
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />

src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StubCodeContext.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ public enum Stage
8080
/// </summary>
8181
public Stage CurrentStage { get; init; } = Stage.Invalid;
8282

83-
/// <summary>
84-
/// <c>CustomTypeMarshallingDirection.In</c> means method import like <c>[LibraryImport]</c>.
85-
/// <c>CustomTypeMarshallingDirection.Out</c> means method export like in <c>[UnmanagedCallersOnly]</c> or in <c>[JSExport]</c>
86-
/// </summary>
87-
public CustomTypeMarshallingDirection Direction { get; init; } = CustomTypeMarshallingDirection.In;
83+
public MarshalDirection Direction { get; init; } = MarshalDirection.ManagedToUnmanaged;
8884

8985
/// <summary>
9086
/// Gets the currently targeted framework and version for stub code generation.

src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Ancillary.Interop.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
<Nullable>enable</Nullable>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<Description>APIs required for usage of the LibraryImportGenerator and related tools.</Description>
10-
<DefineConstants>$(DefineConstants);LIBRARYIMPORT_GENERATOR_TEST</DefineConstants>
10+
<DefineConstants>$(DefineConstants);ANCILLARY_INTEROP</DefineConstants>
1111
</PropertyGroup>
1212

13+
<ItemGroup>
14+
<Compile Include="../Common/MarshalDirection.cs" Link="Common/MarshalDirection.cs" />
15+
</ItemGroup>
1316
</Project>

src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/MarshalDirection.cs renamed to src/libraries/System.Runtime.InteropServices/tests/Common/MarshalDirection.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
9-
4+
#if ANCILLARY_INTEROP
105
namespace System.Runtime.InteropServices.Marshalling
6+
#else
7+
namespace Microsoft.Interop
8+
#endif
119
{
1210
public enum MarshalDirection
1311
{

0 commit comments

Comments
 (0)