diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/BaseJSGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/BaseJSGenerator.cs index 678c1ae8cbeab3..35f1b29c37ff9b 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/BaseJSGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/BaseJSGenerator.cs @@ -21,7 +21,7 @@ protected BaseJSGenerator(MarshalerType marshalerType, IMarshallingGenerator inn Type = marshalerType; } - public TypeSyntax AsNativeType(TypePositionInfo info) => _inner.AsNativeType(info); + public ManagedTypeInfo AsNativeType(TypePositionInfo info) => _inner.AsNativeType(info); public ParameterSyntax AsParameter(TypePositionInfo info) => _inner.AsParameter(info); public bool IsSupported(TargetFramework target, Version version) => _inner.IsSupported(target, version); public virtual bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => _inner.UsesNativeIdentifier(info, context); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/EmptyJSGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/EmptyJSGenerator.cs index 91db26c4000c3a..1a50568a1fc444 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/EmptyJSGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/EmptyJSGenerator.cs @@ -9,7 +9,7 @@ namespace Microsoft.Interop.JavaScript { internal sealed class EmptyJSGenerator : IJSMarshallingGenerator { - public TypeSyntax AsNativeType(TypePositionInfo info) => info.ManagedType.Syntax; + public ManagedTypeInfo AsNativeType(TypePositionInfo info) => info.ManagedType; public IEnumerable Generate(TypePositionInfo info, StubCodeContext context) => Array.Empty(); public IEnumerable GenerateBind(TypePositionInfo info, StubCodeContext context) => Array.Empty(); public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) => SignatureBehavior.ManagedTypeAndAttributes; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs index 27f13e68272b40..4a39b81cec4016 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs @@ -235,13 +235,13 @@ private IMarshallingGenerator CreateCustomNativeTypeMarshaller(TypePositionInfo ICustomTypeMarshallingStrategy marshallingStrategy; if (marshallerData.HasState) { - marshallingStrategy = new StatefulValueMarshalling(marshallerData.MarshallerType, marshallerData.NativeType.Syntax, marshallerData.Shape); + marshallingStrategy = new StatefulValueMarshalling(marshallerData.MarshallerType, marshallerData.NativeType, marshallerData.Shape); if (marshallerData.Shape.HasFlag(MarshallerShape.CallerAllocatedBuffer)) marshallingStrategy = new StatefulCallerAllocatedBufferMarshalling(marshallingStrategy, marshallerData.MarshallerType.Syntax, marshallerData.BufferElementType.Syntax); } else { - marshallingStrategy = new StatelessValueMarshalling(marshallerData.MarshallerType.Syntax, marshallerData.NativeType.Syntax, marshallerData.Shape); + marshallingStrategy = new StatelessValueMarshalling(marshallerData.MarshallerType.Syntax, marshallerData.NativeType, marshallerData.Shape); if (marshallerData.Shape.HasFlag(MarshallerShape.CallerAllocatedBuffer)) marshallingStrategy = new StatelessCallerAllocatedBufferMarshalling(marshallingStrategy, marshallerData.MarshallerType.Syntax, marshallerData.BufferElementType.Syntax, isLinearCollectionMarshalling: false); @@ -282,7 +282,7 @@ private IMarshallingGenerator CreateNativeCollectionMarshaller( } // Insert the unmanaged element type into the marshaller type - TypeSyntax unmanagedElementType = elementMarshaller.AsNativeType(elementInfo).GetCompatibleGenericTypeParameterSyntax(); + TypeSyntax unmanagedElementType = elementMarshaller.AsNativeType(elementInfo).Syntax.GetCompatibleGenericTypeParameterSyntax(); ManagedTypeInfo marshallerType = marshallerData.MarshallerType; TypeSyntax marshallerTypeSyntax = ReplacePlaceholderSyntaxWithUnmanagedTypeSyntax(marshallerType.Syntax, marshalInfo, unmanagedElementType); marshallerType = marshallerType with @@ -290,14 +290,19 @@ private IMarshallingGenerator CreateNativeCollectionMarshaller( FullTypeName = marshallerTypeSyntax.ToString(), DiagnosticFormattedName = marshallerTypeSyntax.ToString(), }; - TypeSyntax nativeTypeSyntax = ReplacePlaceholderSyntaxWithUnmanagedTypeSyntax(marshallerData.NativeType.Syntax, marshalInfo, unmanagedElementType); + string newNativeTypeName = ReplacePlaceholderSyntaxWithUnmanagedTypeSyntax(marshallerData.NativeType.Syntax, marshalInfo, unmanagedElementType).ToFullString(); + ManagedTypeInfo nativeType = marshallerData.NativeType with + { + FullTypeName = newNativeTypeName, + DiagnosticFormattedName = newNativeTypeName + }; ICustomTypeMarshallingStrategy marshallingStrategy; bool elementIsBlittable = elementMarshaller is BlittableMarshaller; if (marshallerData.HasState) { - marshallingStrategy = new StatefulValueMarshalling(marshallerType, nativeTypeSyntax, marshallerData.Shape); + marshallingStrategy = new StatefulValueMarshalling(marshallerType, nativeType, marshallerData.Shape); if (marshallerData.Shape.HasFlag(MarshallerShape.CallerAllocatedBuffer)) { // Check if the buffer element type is actually the unmanaged element type @@ -320,11 +325,11 @@ private IMarshallingGenerator CreateNativeCollectionMarshaller( { if (elementIsBlittable) { - marshallingStrategy = new StatelessLinearCollectionBlittableElementsMarshalling(marshallerTypeSyntax, nativeTypeSyntax, marshallerData.Shape, marshallerData.CollectionElementType.Syntax, unmanagedElementType, numElementsExpression); + marshallingStrategy = new StatelessLinearCollectionBlittableElementsMarshalling(marshallerTypeSyntax, nativeType, marshallerData.Shape, marshallerData.CollectionElementType.Syntax, unmanagedElementType, numElementsExpression); } else { - marshallingStrategy = new StatelessLinearCollectionNonBlittableElementsMarshalling(marshallerTypeSyntax, nativeTypeSyntax, marshallerData.Shape, unmanagedElementType, elementMarshaller, elementInfo, numElementsExpression); + marshallingStrategy = new StatelessLinearCollectionNonBlittableElementsMarshalling(marshallerTypeSyntax, nativeType, marshallerData.Shape, unmanagedElementType, elementMarshaller, elementInfo, numElementsExpression); } if (marshallerData.Shape.HasFlag(MarshallerShape.CallerAllocatedBuffer)) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/BlittableMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/BlittableMarshaller.cs index bc2de37e5b5486..1e4f5369579083 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/BlittableMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/BlittableMarshaller.cs @@ -15,9 +15,9 @@ public sealed class BlittableMarshaller : IMarshallingGenerator { public bool IsSupported(TargetFramework target, Version version) => true; - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { - return info.ManagedType.Syntax; + return info.ManagedType; } public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) @@ -51,7 +51,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont { yield return FixedStatement( VariableDeclaration( - PointerType(AsNativeType(info)), + PointerType(AsNativeType(info).Syntax), SingletonSeparatedList( VariableDeclarator(Identifier(nativeIdentifier)) .WithInitializer(EqualsValueClause( diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/BoolMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/BoolMarshaller.cs index 7ed1dadeba8822..bdb5cd762f6fec 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/BoolMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/BoolMarshaller.cs @@ -14,12 +14,12 @@ namespace Microsoft.Interop { public abstract class BoolMarshallerBase : IMarshallingGenerator { - private readonly PredefinedTypeSyntax _nativeType; + private readonly ManagedTypeInfo _nativeType; private readonly int _trueValue; private readonly int _falseValue; private readonly bool _compareToTrue; - protected BoolMarshallerBase(PredefinedTypeSyntax nativeType, int trueValue, int falseValue, bool compareToTrue) + protected BoolMarshallerBase(ManagedTypeInfo nativeType, int trueValue, int falseValue, bool compareToTrue) { _nativeType = nativeType; _trueValue = trueValue; @@ -29,7 +29,7 @@ protected BoolMarshallerBase(PredefinedTypeSyntax nativeType, int trueValue, int public bool IsSupported(TargetFramework target, Version version) => true; - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { Debug.Assert(info.ManagedType is SpecialTypeInfo(_, _, SpecialType.System_Boolean)); return _nativeType; @@ -66,7 +66,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont SyntaxKind.SimpleAssignmentExpression, IdentifierName(nativeIdentifier), CastExpression( - AsNativeType(info), + AsNativeType(info).Syntax, ParenthesizedExpression( ConditionalExpression(IdentifierName(managedIdentifier), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(_trueValue)), @@ -119,7 +119,7 @@ public sealed class ByteBoolMarshaller : BoolMarshallerBase /// /// True if the byte should be signed, otherwise false public ByteBoolMarshaller(bool signed) - : base(PredefinedType(Token(signed ? SyntaxKind.SByteKeyword : SyntaxKind.ByteKeyword)), trueValue: 1, falseValue: 0, compareToTrue: false) + : base(new SpecialTypeInfo(signed ? "sbyte" : "byte", signed ? "sbyte" : "byte", signed ? SpecialType.System_SByte : SpecialType.System_Byte), trueValue: 1, falseValue: 0, compareToTrue: false) { } } @@ -137,7 +137,7 @@ public sealed class WinBoolMarshaller : BoolMarshallerBase /// /// True if the int should be signed, otherwise false public WinBoolMarshaller(bool signed) - : base(PredefinedType(Token(signed ? SyntaxKind.IntKeyword : SyntaxKind.UIntKeyword)), trueValue: 1, falseValue: 0, compareToTrue: false) + : base(new SpecialTypeInfo(signed ? "int" : "uint", signed ? "int" : "uint", signed ? SpecialType.System_Int32 : SpecialType.System_UInt32), trueValue: 1, falseValue: 0, compareToTrue: false) { } } @@ -150,7 +150,7 @@ public sealed class VariantBoolMarshaller : BoolMarshallerBase private const short VARIANT_TRUE = -1; private const short VARIANT_FALSE = 0; public VariantBoolMarshaller() - : base(PredefinedType(Token(SyntaxKind.ShortKeyword)), trueValue: VARIANT_TRUE, falseValue: VARIANT_FALSE, compareToTrue: true) + : base(new SpecialTypeInfo("short", "short", SpecialType.System_Int16), trueValue: VARIANT_TRUE, falseValue: VARIANT_FALSE, compareToTrue: true) { } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshaller.cs index def4ae4686a0cc..f26ff8c6076a6a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshaller.cs @@ -14,7 +14,7 @@ namespace Microsoft.Interop { public sealed class Utf16CharMarshaller : IMarshallingGenerator { - private static readonly PredefinedTypeSyntax s_nativeType = PredefinedType(Token(SyntaxKind.UShortKeyword)); + private static readonly ManagedTypeInfo s_nativeType = new SpecialTypeInfo("ushort", "ushort", SpecialType.System_UInt16); public Utf16CharMarshaller() { @@ -36,7 +36,7 @@ public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, Stu return ValueBoundaryBehavior.AddressOfNativeIdentifier; } - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { Debug.Assert(info.ManagedType is SpecialTypeInfo(_, _, SpecialType.System_Char)); return s_nativeType; @@ -70,12 +70,12 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont ), // ushort* = (ushort*); LocalDeclarationStatement( - VariableDeclaration(PointerType(AsNativeType(info)), + VariableDeclaration(PointerType(AsNativeType(info).Syntax), SingletonSeparatedList( VariableDeclarator(nativeIdentifier) .WithInitializer(EqualsValueClause( CastExpression( - PointerType(AsNativeType(info)), + PointerType(AsNativeType(info).Syntax), IdentifierName(PinnedIdentifier(info.InstanceIdentifier)))))))) ); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomTypeMarshallingGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomTypeMarshallingGenerator.cs index 012dc6fc9cbd75..915d752ac997db 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomTypeMarshallingGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomTypeMarshallingGenerator.cs @@ -33,7 +33,7 @@ public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, Stu return info.IsByRef ? ValueBoundaryBehavior.AddressOfNativeIdentifier : ValueBoundaryBehavior.NativeIdentifier; } - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { return _nativeTypeMarshaller.AsNativeType(info); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DelegateMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DelegateMarshaller.cs index 00c7f6e2b941b0..c461a844bd2649 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DelegateMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DelegateMarshaller.cs @@ -14,9 +14,9 @@ public sealed class DelegateMarshaller : IMarshallingGenerator { public bool IsSupported(TargetFramework target, Version version) => true; - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { - return MarshallerHelpers.SystemIntPtrType; + return SpecialTypeInfo.IntPtr; } public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ElementsMarshalling.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ElementsMarshalling.cs index e75b25eab45d73..72aa90c0bde6c5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ElementsMarshalling.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ElementsMarshalling.cs @@ -377,7 +377,7 @@ protected StatementSyntax GenerateContentsMarshallingStatement( List(_elementMarshaller.Generate(localElementInfo, elementSetupSubContext) .Concat(elementStatements))); - if (_elementMarshaller.AsNativeType(_elementInfo) is PointerTypeSyntax elementNativeType) + if (_elementMarshaller.AsNativeType(_elementInfo).Syntax is PointerTypeSyntax elementNativeType) { PointerNativeTypeAssignmentRewriter rewriter = new(elementSetupSubContext.GetIdentifiers(localElementInfo).native, elementNativeType); marshallingStatement = (StatementSyntax)rewriter.Visit(marshallingStatement); diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs index 561673d501318c..eb3a4bada79e0f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs @@ -15,9 +15,9 @@ public sealed class Forwarder : IMarshallingGenerator { public bool IsSupported(TargetFramework target, Version version) => true; - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { - return info.ManagedType.Syntax; + return info.ManagedType; } public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomTypeMarshallingStrategy.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomTypeMarshallingStrategy.cs index a3b92f6f4f0399..f9da5d32b39778 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomTypeMarshallingStrategy.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomTypeMarshallingStrategy.cs @@ -11,7 +11,7 @@ namespace Microsoft.Interop /// internal interface ICustomTypeMarshallingStrategy { - TypeSyntax AsNativeType(TypePositionInfo info); + ManagedTypeInfo AsNativeType(TypePositionInfo info); IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context); diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs index ca32e4280f69fc..4e6a749af66a52 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs @@ -85,8 +85,8 @@ public interface IMarshallingGenerator /// Get the native type syntax for /// /// Object to marshal - /// Type syntax for the native type representing - TypeSyntax AsNativeType(TypePositionInfo info); + /// Managed type info for the native type representing + ManagedTypeInfo AsNativeType(TypePositionInfo info); /// /// Get shape that represents the provided in the native signature diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorExtensions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorExtensions.cs index 985328187b76d6..6406f87799a197 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorExtensions.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorExtensions.cs @@ -22,8 +22,8 @@ public static TypeSyntax AsReturnType(this IMarshallingGenerator generator, Type return generator.GetNativeSignatureBehavior(info) switch { SignatureBehavior.ManagedTypeAndAttributes => info.ManagedType.Syntax, - SignatureBehavior.NativeType => generator.AsNativeType(info), - SignatureBehavior.PointerToNativeType => PointerType(generator.AsNativeType(info)), + SignatureBehavior.NativeType => generator.AsNativeType(info).Syntax, + SignatureBehavior.PointerToNativeType => PointerType(generator.AsNativeType(info).Syntax), _ => throw new InvalidOperationException() }; } @@ -62,8 +62,8 @@ public static ParameterSyntax AsParameter(this IMarshallingGenerator generator, return Parameter(Identifier(info.InstanceIdentifier)) .WithType(behavior switch { - SignatureBehavior.NativeType => generator.AsNativeType(info), - SignatureBehavior.PointerToNativeType => PointerType(generator.AsNativeType(info)), + SignatureBehavior.NativeType => generator.AsNativeType(info).Syntax, + SignatureBehavior.PointerToNativeType => PointerType(generator.AsNativeType(info).Syntax), _ => throw new InvalidOperationException() }); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/SafeHandleMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/SafeHandleMarshaller.cs index 363fc3846637af..533cdc4ef194d0 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/SafeHandleMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/SafeHandleMarshaller.cs @@ -18,9 +18,9 @@ public bool IsSupported(TargetFramework target, Version version) return target is TargetFramework.Net && version.Major >= 6; } - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { - return MarshallerHelpers.SystemIntPtrType; + return SpecialTypeInfo.IntPtr; } public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) @@ -117,7 +117,7 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont { yield return LocalDeclarationStatement( VariableDeclaration( - AsNativeType(info), + AsNativeType(info).Syntax, SingletonSeparatedList( VariableDeclarator(handleValueBackupIdentifier) .WithInitializer(EqualsValueClause( diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StatefulMarshallingStrategy.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StatefulMarshallingStrategy.cs index 31918c3ae6a06b..8aa9ce5f340b73 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StatefulMarshallingStrategy.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StatefulMarshallingStrategy.cs @@ -15,19 +15,19 @@ internal sealed class StatefulValueMarshalling : ICustomTypeMarshallingStrategy { internal const string MarshallerIdentifier = "marshaller"; private readonly ManagedTypeInfo _marshallerType; - private readonly TypeSyntax _nativeTypeSyntax; + private readonly ManagedTypeInfo _unmanagedType; private readonly MarshallerShape _shape; - public StatefulValueMarshalling(ManagedTypeInfo marshallerType, TypeSyntax nativeTypeSyntax, MarshallerShape shape) + public StatefulValueMarshalling(ManagedTypeInfo marshallerType, ManagedTypeInfo unmanagedType, MarshallerShape shape) { _marshallerType = marshallerType; - _nativeTypeSyntax = nativeTypeSyntax; + _unmanagedType = unmanagedType; _shape = shape; } - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { - return _nativeTypeSyntax; + return _unmanagedType; } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => true; @@ -210,7 +210,7 @@ public StatefulCallerAllocatedBufferMarshalling(ICustomTypeMarshallingStrategy i _bufferElementType = bufferElementType; } - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { return _innerMarshaller.AsNativeType(info); } @@ -306,7 +306,7 @@ public StatefulLinearCollectionBlittableElementsMarshalling( _numElementsExpression = numElementsExpression; } - public TypeSyntax AsNativeType(TypePositionInfo info) => _innerMarshaller.AsNativeType(info); + public ManagedTypeInfo AsNativeType(TypePositionInfo info) => _innerMarshaller.AsNativeType(info); public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) => _innerMarshaller.GenerateCleanupStatements(info, context); public IEnumerable GenerateGuaranteedUnmarshalStatements(TypePositionInfo info, StubCodeContext context) => _innerMarshaller.GenerateGuaranteedUnmarshalStatements(info, context); @@ -446,7 +446,7 @@ public StatefulLinearCollectionNonBlittableElementsMarshalling( _numElementsExpression = numElementsExpression; } - public TypeSyntax AsNativeType(TypePositionInfo info) => _innerMarshaller.AsNativeType(info); + public ManagedTypeInfo AsNativeType(TypePositionInfo info) => _innerMarshaller.AsNativeType(info); public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) { StatementSyntax elementCleanup = GenerateElementCleanupStatement(info, context); diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StatelessMarshallingStrategy.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StatelessMarshallingStrategy.cs index aa09b9d8d3d01e..2374f50b6dd696 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StatelessMarshallingStrategy.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StatelessMarshallingStrategy.cs @@ -18,19 +18,19 @@ namespace Microsoft.Interop internal sealed class StatelessValueMarshalling : ICustomTypeMarshallingStrategy { private readonly TypeSyntax _marshallerTypeSyntax; - private readonly TypeSyntax _nativeTypeSyntax; + private readonly ManagedTypeInfo _unmanagedType; private readonly MarshallerShape _shape; - public StatelessValueMarshalling(TypeSyntax marshallerTypeSyntax, TypeSyntax nativeTypeSyntax, MarshallerShape shape) + public StatelessValueMarshalling(TypeSyntax marshallerTypeSyntax, ManagedTypeInfo unmanagedType, MarshallerShape shape) { _marshallerTypeSyntax = marshallerTypeSyntax; - _nativeTypeSyntax = nativeTypeSyntax; + _unmanagedType = unmanagedType; _shape = shape; } - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { - return _nativeTypeSyntax; + return _unmanagedType; } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => true; @@ -141,7 +141,7 @@ public StatelessCallerAllocatedBufferMarshalling(ICustomTypeMarshallingStrategy _isLinearCollectionMarshalling = isLinearCollectionMarshalling; } - public TypeSyntax AsNativeType(TypePositionInfo info) => _innerMarshaller.AsNativeType(info); + public ManagedTypeInfo AsNativeType(TypePositionInfo info) => _innerMarshaller.AsNativeType(info); public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) => _innerMarshaller.GenerateCleanupStatements(info, context); public IEnumerable GenerateGuaranteedUnmarshalStatements(TypePositionInfo info, StubCodeContext context) => _innerMarshaller.GenerateGuaranteedUnmarshalStatements(info, context); @@ -247,7 +247,7 @@ public StatelessFreeMarshalling(ICustomTypeMarshallingStrategy innerMarshaller, _marshallerType = marshallerType; } - public TypeSyntax AsNativeType(TypePositionInfo info) => _innerMarshaller.AsNativeType(info); + public ManagedTypeInfo AsNativeType(TypePositionInfo info) => _innerMarshaller.AsNativeType(info); public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) { @@ -282,22 +282,22 @@ public IEnumerable GenerateCleanupStatements(TypePositionInfo i internal sealed class StatelessLinearCollectionBlittableElementsMarshalling : BlittableElementsMarshalling, ICustomTypeMarshallingStrategy { private readonly TypeSyntax _marshallerTypeSyntax; - private readonly TypeSyntax _nativeTypeSyntax; + private readonly ManagedTypeInfo _unmanagedType; private readonly MarshallerShape _shape; private readonly ExpressionSyntax _numElementsExpression; - public StatelessLinearCollectionBlittableElementsMarshalling(TypeSyntax marshallerTypeSyntax, TypeSyntax nativeTypeSyntax, MarshallerShape shape, TypeSyntax managedElementType, TypeSyntax unmanagedElementType, ExpressionSyntax numElementsExpression) + public StatelessLinearCollectionBlittableElementsMarshalling(TypeSyntax marshallerTypeSyntax, ManagedTypeInfo unmanagedType, MarshallerShape shape, TypeSyntax managedElementType, TypeSyntax unmanagedElementType, ExpressionSyntax numElementsExpression) : base(managedElementType, unmanagedElementType) { _marshallerTypeSyntax = marshallerTypeSyntax; - _nativeTypeSyntax = nativeTypeSyntax; + _unmanagedType = unmanagedType; _shape = shape; _numElementsExpression = numElementsExpression; } - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { - return _nativeTypeSyntax; + return _unmanagedType; } public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) => Array.Empty(); @@ -502,13 +502,13 @@ protected override InvocationExpressionSyntax GetManagedValuesDestination(TypePo internal sealed class StatelessLinearCollectionNonBlittableElementsMarshalling : NonBlittableElementsMarshalling, ICustomTypeMarshallingStrategy { private readonly TypeSyntax _marshallerTypeSyntax; - private readonly TypeSyntax _nativeTypeSyntax; + private readonly ManagedTypeInfo _unmanagedType; private readonly MarshallerShape _shape; private readonly ExpressionSyntax _numElementsExpression; public StatelessLinearCollectionNonBlittableElementsMarshalling( TypeSyntax marshallerTypeSyntax, - TypeSyntax nativeTypeSyntax, + ManagedTypeInfo unmanagedType, MarshallerShape shape, TypeSyntax unmanagedElementType, IMarshallingGenerator elementMarshaller, @@ -517,12 +517,12 @@ public StatelessLinearCollectionNonBlittableElementsMarshalling( : base (unmanagedElementType, elementMarshaller, elementInfo) { _marshallerTypeSyntax = marshallerTypeSyntax; - _nativeTypeSyntax = nativeTypeSyntax; + _unmanagedType = unmanagedType; _shape = shape; _numElementsExpression = numElementsExpression; } - public TypeSyntax AsNativeType(TypePositionInfo info) => _nativeTypeSyntax; + public ManagedTypeInfo AsNativeType(TypePositionInfo info) => _unmanagedType; public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StaticPinnableManagedValueMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StaticPinnableManagedValueMarshaller.cs index cf4d8b9b802232..91d43dc9bf8c7b 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StaticPinnableManagedValueMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StaticPinnableManagedValueMarshaller.cs @@ -28,7 +28,7 @@ public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, Stu { if (IsPinningPathSupported(info, context)) { - if (AsNativeType(info) is PointerTypeSyntax pointerType + if (AsNativeType(info).Syntax is PointerTypeSyntax pointerType && pointerType.ElementType is PredefinedTypeSyntax predefinedType && predefinedType.Keyword.IsKind(SyntaxKind.VoidKeyword)) { @@ -42,7 +42,7 @@ public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, Stu return _innerMarshallingGenerator.GetValueBoundaryBehavior(info, context); } - public TypeSyntax AsNativeType(TypePositionInfo info) + public ManagedTypeInfo AsNativeType(TypePositionInfo info) { return _innerMarshallingGenerator.AsNativeType(info); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/VariableDeclarations.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/VariableDeclarations.cs index dbc73df2f8d2c0..56acdddb76b08d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/VariableDeclarations.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/VariableDeclarations.cs @@ -72,7 +72,7 @@ static void AppendVariableDeclarations(ImmutableArray