Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7287a88
Refactor PInvokeStubContext into SignatureContext and ContainingSynta…
jkoritzinsky Apr 12, 2022
e7bc960
Remove some legacy designs as we evolved away from being a simple wra…
jkoritzinsky Apr 12, 2022
feceaa9
Unify processing for common named arguments.
jkoritzinsky Apr 12, 2022
96a00ad
Refactor most logic out of PInvokeStubCodeGenerator to make new gener…
jkoritzinsky Apr 13, 2022
211f1c8
Fix array casting
jkoritzinsky Apr 13, 2022
3eef9eb
Fix missing stage
jkoritzinsky Apr 13, 2022
4738247
Refactor context construction
jkoritzinsky Apr 13, 2022
8d03506
Update diagnostics
jkoritzinsky Apr 14, 2022
90e8802
With the new handling for diagnostic steps, the step ordering in our …
jkoritzinsky Apr 14, 2022
f2e2fe3
Remove the need to pass the original syntax through the pipeline (rol…
jkoritzinsky Apr 14, 2022
db18755
Merge branch 'main' into share-more-code
jkoritzinsky Apr 14, 2022
6fa932f
Merge branch 'main' into share-more-code
jkoritzinsky Apr 20, 2022
6c75536
Merge branch 'main' of github.com:dotnet/runtime into share-more-code
jkoritzinsky Apr 21, 2022
2b932b2
Merge branch 'main' of github.com:dotnet/runtime into share-more-code
jkoritzinsky May 10, 2022
747cc2c
PR feedback.
jkoritzinsky May 10, 2022
4c0f043
Fix build
jkoritzinsky May 11, 2022
6e1dbfb
Merge branch 'main' of github.com:dotnet/runtime into share-more-code
jkoritzinsky May 11, 2022
7e54c0b
Fix namespaces
jkoritzinsky May 11, 2022
82bc31d
Fix build breaks.
jkoritzinsky May 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.ComponentModel;

#if MICROSOFT_INTEROP_SOURCEGENERATION
namespace Microsoft.Interop
#else
namespace System.Runtime.InteropServices.Marshalling
#endif
{
/// <summary>
/// A direction of marshalling data into or out of the managed environment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;

#if MICROSOFT_INTEROP_SOURCEGENERATION
namespace Microsoft.Interop
#else
namespace System.Runtime.InteropServices.Marshalling
#endif
{
/// <summary>
/// Optional features supported by custom type marshallers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if MICROSOFT_INTEROP_SOURCEGENERATION
namespace Microsoft.Interop
#else
namespace System.Runtime.InteropServices.Marshalling
#endif
{
/// <summary>
/// The shape of a custom type marshaller for usage in source-generated interop scenarios.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
//
// Types in this file are used for generated p/invokes
//
#if MICROSOFT_INTEROP_SOURCEGENERATION
namespace Microsoft.Interop
#else
namespace System.Runtime.InteropServices
#endif
{
/// <summary>
/// Specifies how strings should be marshalled for generated p/invokes
/// </summary>
#if SYSTEM_PRIVATE_CORELIB
#if SYSTEM_PRIVATE_CORELIB || MICROSOFT_INTEROP_SOURCEGENERATION
public
#else
internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Composition;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,10 @@ namespace Microsoft.Interop
{
internal static class Comparers
{
/// <summary>
/// Comparer for the set of all of the generated stubs and diagnostics generated for each of them.
/// </summary>
public static readonly IEqualityComparer<ImmutableArray<(string, ImmutableArray<Diagnostic>)>> GeneratedSourceSet = new ImmutableArraySequenceEqualComparer<(string, ImmutableArray<Diagnostic>)>(new CustomValueTupleElementComparer<string, ImmutableArray<Diagnostic>>(EqualityComparer<string>.Default, new ImmutableArraySequenceEqualComparer<Diagnostic>(EqualityComparer<Diagnostic>.Default)));

/// <summary>
/// Comparer for an individual generated stub source as a string and the generated diagnostics for the stub.
/// </summary>
public static readonly IEqualityComparer<(string, ImmutableArray<Diagnostic>)> GeneratedSource = new CustomValueTupleElementComparer<string, ImmutableArray<Diagnostic>>(EqualityComparer<string>.Default, new ImmutableArraySequenceEqualComparer<Diagnostic>(EqualityComparer<Diagnostic>.Default));

/// <summary>
/// Comparer for an individual generated stub source as a syntax tree and the generated diagnostics for the stub.
/// </summary>
public static readonly IEqualityComparer<(MemberDeclarationSyntax Syntax, ImmutableArray<Diagnostic> Diagnostics)> GeneratedSyntax = new CustomValueTupleElementComparer<MemberDeclarationSyntax, ImmutableArray<Diagnostic>>(SyntaxEquivalentComparer.Instance, new ImmutableArraySequenceEqualComparer<Diagnostic>(EqualityComparer<Diagnostic>.Default));

/// <summary>
/// Comparer for the context used to generate a stub and the original user-provided syntax that triggered stub creation.
/// </summary>
public static readonly IEqualityComparer<(MethodDeclarationSyntax Syntax, LibraryImportGenerator.IncrementalStubGenerationContext StubContext)> CalculatedContextWithSyntax = new CustomValueTupleElementComparer<MethodDeclarationSyntax, LibraryImportGenerator.IncrementalStubGenerationContext>(SyntaxEquivalentComparer.Instance, EqualityComparer<LibraryImportGenerator.IncrementalStubGenerationContext>.Default);
}

/// <summary>
Expand Down Expand Up @@ -61,23 +46,6 @@ public int GetHashCode(ImmutableArray<T> obj)
}
}

internal sealed class SyntaxEquivalentComparer : IEqualityComparer<SyntaxNode>
{
public static readonly SyntaxEquivalentComparer Instance = new();

private SyntaxEquivalentComparer() { }

public bool Equals(SyntaxNode x, SyntaxNode y)
{
return x.IsEquivalentTo(y);
}

public int GetHashCode(SyntaxNode obj)
{
throw new UnreachableException();
}
}

internal sealed class CustomValueTupleElementComparer<T, U> : IEqualityComparer<(T, U)>
{
private readonly IEqualityComparer<T> _item1Comparer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ public void ReportConfigurationNotSupported(
/// <summary>
/// Report diagnostic for marshalling of a parameter/return that is not supported
/// </summary>
/// <param name="method">Method with the parameter/return</param>
/// <param name="diagnosticLocations">Method with the parameter/return</param>
/// <param name="info">Type info for the parameter/return</param>
/// <param name="notSupportedDetails">[Optional] Specific reason for lack of support</param>
public void ReportMarshallingNotSupported(
MethodDeclarationSyntax method,
MethodSignatureDiagnosticLocations diagnosticLocations,
TypePositionInfo info,
string? notSupportedDetails,
ImmutableDictionary<string, string> diagnosticProperties)
Expand All @@ -224,15 +224,14 @@ public void ReportMarshallingNotSupported(

if (info.IsManagedReturnPosition)
{
diagnosticLocation = Location.Create(method.SyntaxTree, method.Identifier.Span);
elementName = method.Identifier.ValueText;
diagnosticLocation = diagnosticLocations.FallbackLocation;
elementName = diagnosticLocations.MethodIdentifier;
}
else
{
Debug.Assert(info.ManagedIndex <= method.ParameterList.Parameters.Count);
ParameterSyntax param = method.ParameterList.Parameters[info.ManagedIndex];
diagnosticLocation = Location.Create(param.SyntaxTree, param.Identifier.Span);
elementName = param.Identifier.ValueText;
Debug.Assert(info.ManagedIndex <= diagnosticLocations.ManagedParameterLocations.Length);
diagnosticLocation = diagnosticLocations.ManagedParameterLocations[info.ManagedIndex];
elementName = info.InstanceIdentifier;
}

if (!string.IsNullOrEmpty(notSupportedDetails))
Expand Down Expand Up @@ -322,12 +321,12 @@ public void ReportInvalidMarshallingAttributeInfo(
/// <param name="method">Method with the configuration that cannot be forwarded</param>
/// <param name="name">Configuration name</param>
/// <param name="value">Configuration value</param>
public void ReportCannotForwardToDllImport(MethodDeclarationSyntax method, string name, string? value = null)
public void ReportCannotForwardToDllImport(MethodSignatureDiagnosticLocations method, string name, string? value = null)
{
_diagnostics.Add(
Diagnostic.Create(
CannotForwardToDllImport,
Location.Create(method.SyntaxTree, method.Identifier.Span),
method.FallbackLocation,
value is null ? name : $"{name}={value}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,11 @@

namespace Microsoft.Interop
{
/// <summary>
/// Flags used to indicate members on LibraryImport attribute.
/// </summary>
[Flags]
public enum LibraryImportMember
{
None = 0,
EntryPoint = 1 << 0,
SetLastError = 1 << 1,
StringMarshalling = 1 << 2,
StringMarshallingCustomType = 1 << 3,
All = ~None
}

/// <summary>
/// LibraryImportAttribute data
/// </summary>
internal sealed record LibraryImportData(string ModuleName)
internal sealed record LibraryImportData(string ModuleName) : InteropAttributeData
{
/// <summary>
/// Value set by the user on the original declaration.
/// </summary>
public LibraryImportMember IsUserDefined { get; init; }
public string? EntryPoint { get; init; }
public bool SetLastError { get; init; }
public StringMarshalling StringMarshalling { get; init; }
public INamedTypeSymbol? StringMarshallingCustomType { get; init; }
public string EntryPoint { get; init; }
}
}
Loading