From 3c621aad03d46b75abf2accf27805806b212e676 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 15 Jun 2023 20:36:10 -0700 Subject: [PATCH 1/8] Refactor how diagnostics work in the interop generators Update the diagnostics system to have the following characteristics: - Well known categories of diagnostics, such as "Not supported" or "Unnecessary data" are represented by a discriminated union. - Each generator provides diagnostic descriptors that fit specific formatting rules for each check (which all of our generators follow) - Slightly abstract out the concept of "diagnostic" locations so it can be shared better. - Split "create diagnostic" from "report diagnostic" to make it easier to share code. - Remove our exception type and move to a "generator and a collection of possibly fatal diagnostics" model to enable representing diagnostics that shouldn't stop source-generated interop codegen. --- .../JSImportGenerator/DescriptorProvider.cs | 25 ++ .../JSImportGenerator/GeneratorDiagnostics.cs | 157 +---------- .../JSExportCodeGenerator.cs | 8 +- .../JSImportGenerator/JSExportGenerator.cs | 16 +- .../JSImportGenerator/JSGeneratorFactory.cs | 254 +++++++++--------- .../JSImportCodeGenerator.cs | 8 +- .../JSImportGenerator/JSImportGenerator.cs | 16 +- .../JSImportGenerator/JSSignatureContext.cs | 2 +- .../Marshaling/FuncJSGenerator.cs | 9 - ...omImportToGeneratedComInterfaceAnalyzer.cs | 40 ++- .../ComInterfaceGenerator.cs | 9 +- .../DiagnosticDescriptorProvider.cs | 30 +++ .../GeneratorDiagnostics.cs | 170 ++---------- .../ComInterfaceDispatchMarshallerFactory.cs | 4 +- ...anagedHResultExceptionMarshallerFactory.cs | 6 +- .../ObjectUnwrapperMarshallerFactory.cs | 4 +- .../Resources/Strings.resx | 62 +++-- .../Resources/xlf/Strings.cs.xlf | 10 + .../Resources/xlf/Strings.de.xlf | 10 + .../Resources/xlf/Strings.es.xlf | 10 + .../Resources/xlf/Strings.fr.xlf | 10 + .../Resources/xlf/Strings.it.xlf | 10 + .../Resources/xlf/Strings.ja.xlf | 10 + .../Resources/xlf/Strings.ko.xlf | 10 + .../Resources/xlf/Strings.pl.xlf | 10 + .../Resources/xlf/Strings.pt-BR.xlf | 10 + .../Resources/xlf/Strings.ru.xlf | 10 + .../Resources/xlf/Strings.tr.xlf | 10 + .../Resources/xlf/Strings.zh-Hans.xlf | 10 + .../Resources/xlf/Strings.zh-Hant.xlf | 10 + .../UnmanagedToManagedStubGenerator.cs | 8 +- .../VirtualMethodPointerStubGenerator.cs | 16 +- .../VtableIndexStubGenerator.cs | 14 +- .../Common/DefaultMarshallingInfoParser.cs | 2 +- .../ConvertToLibraryImportAnalyzer.cs | 26 +- .../DiagnosticDescriptorProvider.cs | 28 ++ .../ForwarderMarshallingGeneratorFactory.cs | 2 +- .../GeneratorDiagnostics.cs | 171 ++---------- .../LibraryImportGenerator.cs | 18 +- .../PInvokeStubCodeGenerator.cs | 8 +- .../Resources/Strings.resx | 62 +++-- .../Resources/xlf/Strings.cs.xlf | 10 + .../Resources/xlf/Strings.de.xlf | 10 + .../Resources/xlf/Strings.es.xlf | 10 + .../Resources/xlf/Strings.fr.xlf | 10 + .../Resources/xlf/Strings.it.xlf | 10 + .../Resources/xlf/Strings.ja.xlf | 10 + .../Resources/xlf/Strings.ko.xlf | 10 + .../Resources/xlf/Strings.pl.xlf | 10 + .../Resources/xlf/Strings.pt-BR.xlf | 10 + .../Resources/xlf/Strings.ru.xlf | 10 + .../Resources/xlf/Strings.tr.xlf | 10 + .../Resources/xlf/Strings.zh-Hans.xlf | 10 + .../Resources/xlf/Strings.zh-Hant.xlf | 10 + .../BoundGenerators.cs | 32 ++- .../CustomMarshallingInfoHelper.cs | 4 +- .../DiagnosticInfo.cs | 6 +- .../MarshalAsAttributeParser.cs | 4 +- .../MarshalUsingAttributeParser.cs | 4 +- ...ributedMarshallingModelGeneratorFactory.cs | 118 +++++--- .../ByValueContentsMarshalKindValidator.cs | 30 ++- .../CharMarshallingGeneratorFactory.cs | 22 +- .../Marshalling/GeneratorDiagnostic.cs | 63 +++++ .../IMarshallingGeneratorFactory.cs | 6 +- .../MarshalAsMarshallingGeneratorFactory.cs | 34 +-- .../Marshalling/MarshallingGenerator.cs | 38 --- ...oMarshallingInfoErrorMarshallingFactory.cs | 6 +- .../Marshalling/ResolvedGenerator.cs | 32 +++ .../UnsupportedMarshallingFactory.cs | 10 +- .../MarshallingInfoParser.cs | 8 +- ...=> MarshallingInfoParserDiagnosticsBag.cs} | 71 ++++- .../MethodSignatureDiagnosticLocations.cs | 25 +- .../MethodSignatureElementInfoProvider.cs | 4 +- .../NativeMarshallingAttributeParser.cs | 4 +- .../StringMarshallingInfoProvider.cs | 4 +- .../SymbolDiagnosticLocations.cs | 50 ++++ .../UseSiteAttributeProvider.cs | 4 +- .../Diagnostics.cs | 12 +- 78 files changed, 1125 insertions(+), 901 deletions(-) create mode 100644 src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/DescriptorProvider.cs create mode 100644 src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs create mode 100644 src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs create mode 100644 src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/GeneratorDiagnostic.cs create mode 100644 src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ResolvedGenerator.cs rename src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/{IGeneratorDiagnostics.cs => MarshallingInfoParserDiagnosticsBag.cs} (72%) create mode 100644 src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SymbolDiagnosticLocations.cs diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/DescriptorProvider.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/DescriptorProvider.cs new file mode 100644 index 00000000000000..0db6708469b374 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/DescriptorProvider.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.CodeAnalysis; + +namespace Microsoft.Interop.JavaScript +{ + internal sealed class DescriptorProvider : IDiagnosticDescriptorProvider + { + public DiagnosticDescriptor InvalidMarshallingAttributeInfo => GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported; + + public DiagnosticDescriptor GetConfigurationNotSupportedDescriptor(bool withValue) => withValue ? GeneratorDiagnostics.ConfigurationValueNotSupported : GeneratorDiagnostics.ConfigurationNotSupported; + + public DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic) + { + return diagnostic switch + { + GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, + GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, + { TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupported, + { TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupported, + }; + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/GeneratorDiagnostics.cs index 1cd066f0d9255b..459cbb8e12b462 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/GeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/GeneratorDiagnostics.cs @@ -13,7 +13,7 @@ namespace Microsoft.Interop /// /// Class for reporting diagnostics in the library import generator /// - public class GeneratorDiagnostics : IGeneratorDiagnostics + public static class GeneratorDiagnostics { public class Ids { @@ -28,145 +28,6 @@ public class Ids } private const string Category = "JSImportGenerator"; - private readonly List _diagnostics = new List(); - - public IEnumerable Diagnostics => _diagnostics; - - public void ReportInvalidMarshallingAttributeInfo( - AttributeData attributeData, - string reasonResourceName, - params string[] reasonArgs) - { - _diagnostics.Add( - attributeData.CreateDiagnosticInfo( - GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported, - new LocalizableResourceString(reasonResourceName, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR), reasonArgs))); - } - - /// - /// Report diagnostic for configuration that is not supported by the DLL import source generator - /// - /// Attribute specifying the unsupported configuration - /// Name of the configuration - /// [Optiona] Unsupported configuration value - public void ReportConfigurationNotSupported( - AttributeData attributeData, - string configurationName, - string? unsupportedValue = null) - { - if (unsupportedValue == null) - { - _diagnostics.Add( - attributeData.CreateDiagnosticInfo( - GeneratorDiagnostics.ConfigurationNotSupported, - configurationName)); - } - else - { - _diagnostics.Add( - attributeData.CreateDiagnosticInfo( - GeneratorDiagnostics.ConfigurationValueNotSupported, - unsupportedValue, - configurationName)); - } - } - - /// - /// Report diagnostic for marshalling of a parameter/return that is not supported - /// - /// Method with the parameter/return - /// Type info for the parameter/return - /// [Optional] Specific reason for lack of support - public void ReportMarshallingNotSupported( - MethodSignatureDiagnosticLocations diagnosticLocations, - TypePositionInfo info, - string? notSupportedDetails, - ImmutableDictionary diagnosticProperties) - { - Location diagnosticLocation = Location.None; - string elementName = string.Empty; - - if (info.IsManagedReturnPosition) - { - diagnosticLocation = diagnosticLocations.FallbackLocation; - elementName = diagnosticLocations.MethodIdentifier; - } - else - { - Debug.Assert(info.ManagedIndex <= diagnosticLocations.ManagedParameterLocations.Length); - diagnosticLocation = diagnosticLocations.ManagedParameterLocations[info.ManagedIndex]; - elementName = info.InstanceIdentifier; - } - - if (!string.IsNullOrEmpty(notSupportedDetails)) - { - // Report the specific not-supported reason. - if (info.IsManagedReturnPosition) - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, - diagnosticProperties, - notSupportedDetails!, - elementName)); - } - else - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, - diagnosticProperties, - notSupportedDetails!, - elementName)); - } - } - else if (info.MarshallingAttributeInfo is MarshalAsInfo) - { - // Report that the specified marshalling configuration is not supported. - // We don't forward marshalling attributes, so this is reported differently - // than when there is no attribute and the type itself is not supported. - if (info.IsManagedReturnPosition) - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ReturnConfigurationNotSupported, - diagnosticProperties, - nameof(System.Runtime.InteropServices.MarshalAsAttribute), - elementName)); - } - else - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ParameterConfigurationNotSupported, - diagnosticProperties, - nameof(System.Runtime.InteropServices.MarshalAsAttribute), - elementName)); - } - } - else - { - // Report that the type is not supported - if (info.IsManagedReturnPosition) - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ReturnTypeNotSupported, - diagnosticProperties, - info.ManagedType.DiagnosticFormattedName, - elementName)); - } - else - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ParameterTypeNotSupported, - diagnosticProperties, - info.ManagedType.DiagnosticFormattedName, - elementName)); - } - } - } public static readonly DiagnosticDescriptor ConfigurationNotSupported = new DiagnosticDescriptor( @@ -209,14 +70,14 @@ public void ReportMarshallingNotSupported( description: GetResourceString(nameof(SR.TypeNotSupportedDescription))); public static readonly DiagnosticDescriptor ParameterTypeNotSupported = - new DiagnosticDescriptor( - Ids.TypeNotSupported, - GetResourceString(nameof(SR.TypeNotSupportedTitle)), - GetResourceString(nameof(SR.TypeNotSupportedMessageParameter)), - Category, - DiagnosticSeverity.Error, - isEnabledByDefault: true, - description: GetResourceString(nameof(SR.TypeNotSupportedDescription))); + new DiagnosticDescriptor( + Ids.TypeNotSupported, + GetResourceString(nameof(SR.TypeNotSupportedTitle)), + GetResourceString(nameof(SR.TypeNotSupportedMessageParameter)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.TypeNotSupportedDescription))); public static readonly DiagnosticDescriptor ReturnTypeNotSupported = new DiagnosticDescriptor( diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportCodeGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportCodeGenerator.cs index 31511e9808fb46..016b4a829b64e2 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportCodeGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportCodeGenerator.cs @@ -25,11 +25,9 @@ public JSExportCodeGenerator( ImmutableArray argTypes, JSExportData attributeData, JSSignatureContext signatureContext, - Action marshallingNotSupportedCallback, + Action marshallingNotSupportedCallback, IMarshallingGeneratorFactory generatorFactory) { - Action extendedInvariantViolationsCallback = (info, details) => - marshallingNotSupportedCallback(info, new MarshallingNotSupportedException(info, _context) { NotSupportedDetails = details }); _signatureContext = signatureContext; NativeToManagedStubCodeContext innerContext = new NativeToManagedStubCodeContext(targetFramework, targetFrameworkVersion, ReturnIdentifier, ReturnIdentifier); _context = new JSExportCodeContext(attributeData, innerContext); @@ -37,7 +35,7 @@ public JSExportCodeGenerator( _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new EmptyJSGenerator(), out var bindingFailures); foreach (var failure in bindingFailures) { - marshallingNotSupportedCallback(failure.Info, failure.Exception); + marshallingNotSupportedCallback(failure); } if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, null)) @@ -53,7 +51,7 @@ public JSExportCodeGenerator( BoundGenerator spanArg = _marshallers.SignatureMarshallers.FirstOrDefault(m => m.TypeInfo.MarshallingAttributeInfo is JSMarshallingInfo(_, JSSpanTypeInfo)); if (spanArg != default) { - marshallingNotSupportedCallback(spanArg.TypeInfo, new MarshallingNotSupportedException(spanArg.TypeInfo, _context) + marshallingNotSupportedCallback(new GeneratorDiagnostic.NotSupported(spanArg.TypeInfo, _context) { NotSupportedDetails = SR.SpanAndTaskNotSupported }); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs index f89ab70d4535ee..8ae94cf87d7635 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs @@ -189,19 +189,21 @@ private static IncrementalStubGenerationContext CalculateStubInformation( Debug.Assert(jsExportAttr is not null); - var generatorDiagnostics = new GeneratorDiagnostics(); + var generatorDiagnostics = new GeneratorDiagnosticBag(); + var descriptorProvider = new DescriptorProvider(); // Process the JSExport attribute JSExportData? jsExportData = ProcessJSExportAttribute(jsExportAttr!); if (jsExportData is null) { - generatorDiagnostics.ReportConfigurationNotSupported(jsExportAttr!, "Invalid syntax"); + generatorDiagnostics.ReportConfigurationNotSupported(descriptorProvider, jsExportAttr!, "Invalid syntax"); jsExportData = new JSExportData(); } // Create the stub. - var signatureContext = JSSignatureContext.Create(symbol, environment, generatorDiagnostics, ct); + var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(descriptorProvider, generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); + var signatureContext = JSSignatureContext.Create(symbol, environment, marshallingInfoParserDiagnosticBag, ct); var containingTypeContext = new ContainingSyntaxContext(originalSyntax); @@ -289,7 +291,9 @@ private static NamespaceDeclarationSyntax GenerateRegSource( private static (MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray) GenerateSource( IncrementalStubGenerationContext incrementalContext) { - var diagnostics = new GeneratorDiagnostics(); + var diagnostics = new GeneratorDiagnosticBag(); + + var descriptorProvider = new DescriptorProvider(); // Generate stub code var stubGenerator = new JSExportCodeGenerator( @@ -298,9 +302,9 @@ private static (MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, I incrementalContext.SignatureContext.SignatureContext.ElementTypeInformation, incrementalContext.JSExportData, incrementalContext.SignatureContext, - (elementInfo, ex) => + ex => { - diagnostics.ReportMarshallingNotSupported(incrementalContext.DiagnosticLocation, elementInfo, ex.NotSupportedDetails, ex.DiagnosticProperties ?? ImmutableDictionary.Empty); + diagnostics.ReportGeneratorDiagnostic(descriptorProvider, incrementalContext.DiagnosticLocation, ex); }, incrementalContext.GeneratorFactoryKey.GeneratorFactory); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSGeneratorFactory.cs index f8ce9bcf1f91c5..b6e529f4dd5b31 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSGeneratorFactory.cs @@ -13,25 +13,25 @@ namespace Microsoft.Interop.JavaScript { internal sealed class JSGeneratorFactory : IMarshallingGeneratorFactory { - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) { Debug.Assert(context != null); if (info.IsByRef || info.ByValueContentsMarshalKind != ByValueContentsMarshalKind.Default) { // out of scope for Net7.0 - throw new MarshallingNotSupportedException(info, context) + return ResolvedGenerator.NotSupported(new(info, context) { NotSupportedDetails = SR.InOutRefNotSupported - }; + }); } JSMarshallingInfo jsMarshalingInfo = info.MarshallingAttributeInfo as JSMarshallingInfo; - Exception fail(string failReason) + ResolvedGenerator fail(string failReason) { - return new MarshallingNotSupportedException(info, context) + return ResolvedGenerator.NotSupported(new(info, context) { NotSupportedDetails = failReason - }; + }); } bool isToJs = info.ManagedIndex != TypePositionInfo.ReturnIndex ^ context is JSExportCodeContext; @@ -39,18 +39,18 @@ Exception fail(string failReason) { // invalid case { TypeInfo: JSInvalidTypeInfo }: - throw new MarshallingNotSupportedException(info, context); + return ResolvedGenerator.NotSupported(new(info, context)); // void case { TypeInfo: JSSimpleTypeInfo(KnownManagedType.Void), JSType: JSTypeFlags.Discard }: case { TypeInfo: JSSimpleTypeInfo(KnownManagedType.Void), JSType: JSTypeFlags.Void }: case { TypeInfo: JSSimpleTypeInfo(KnownManagedType.Void), JSType: JSTypeFlags.None }: case { TypeInfo: JSSimpleTypeInfo(KnownManagedType.Void), JSType: JSTypeFlags.Missing }: - return new VoidGenerator(jsMarshalingInfo.JSType == JSTypeFlags.Void ? MarshalerType.Void : MarshalerType.Discard); + return ResolvedGenerator.Resolved(new VoidGenerator(jsMarshalingInfo.JSType == JSTypeFlags.Void ? MarshalerType.Void : MarshalerType.Discard)); // discard no void case { JSType: JSTypeFlags.Discard }: - throw fail(SR.DiscardOnlyVoid); + return fail(SR.DiscardOnlyVoid); // primitive case { TypeInfo: JSSimpleTypeInfo simple }: @@ -83,179 +83,179 @@ Exception fail(string failReason) return Create(info, isToJs, function.KnownType, function.ArgsTypeInfo.Select(a => a.KnownType).ToArray(), jsMarshalingInfo.JSType, jsMarshalingInfo.JSTypeArguments, fail); default: - throw new MarshallingNotSupportedException(info, context); + return ResolvedGenerator.NotSupported(new(info, context)); } } - internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, KnownManagedType marshaledType, KnownManagedType[] argumentTypes, JSTypeFlags jsType, JSTypeFlags[] jsTypeArguments, Func failWithReason) + internal static ResolvedGenerator Create(TypePositionInfo info, bool isToJs, KnownManagedType marshaledType, KnownManagedType[] argumentTypes, JSTypeFlags jsType, JSTypeFlags[] jsTypeArguments, Func failWithReason) { switch (marshaledType) { // primitive - case KnownManagedType.Boolean when jsType == JSTypeFlags.Boolean: return new PrimitiveJSGenerator(MarshalerType.Boolean); - case KnownManagedType.Byte when jsType == JSTypeFlags.Number: return new PrimitiveJSGenerator(MarshalerType.Byte); - case KnownManagedType.Char when jsType == JSTypeFlags.String: return new PrimitiveJSGenerator(MarshalerType.Char); - case KnownManagedType.Int16 when jsType == JSTypeFlags.Number: return new PrimitiveJSGenerator(MarshalerType.Int16); - case KnownManagedType.Int32 when jsType == JSTypeFlags.Number: return new PrimitiveJSGenerator(MarshalerType.Int32); - case KnownManagedType.Int64 when jsType == JSTypeFlags.Number: return new PrimitiveJSGenerator(MarshalerType.Int52); - case KnownManagedType.Int64 when jsType == JSTypeFlags.BigInt: return new PrimitiveJSGenerator(MarshalerType.BigInt64); - case KnownManagedType.Single when jsType == JSTypeFlags.Number: return new PrimitiveJSGenerator(MarshalerType.Single); - case KnownManagedType.Double when jsType == JSTypeFlags.Number: return new PrimitiveJSGenerator(MarshalerType.Double); - case KnownManagedType.IntPtr when jsType == JSTypeFlags.Number: return new PrimitiveJSGenerator(MarshalerType.IntPtr); - case KnownManagedType.DateTime when jsType == JSTypeFlags.Date: return new PrimitiveJSGenerator(MarshalerType.DateTime); - case KnownManagedType.DateTimeOffset when jsType == JSTypeFlags.Date: return new PrimitiveJSGenerator(MarshalerType.DateTimeOffset); - case KnownManagedType.Exception when jsType == JSTypeFlags.Error: return new PrimitiveJSGenerator(MarshalerType.Exception); - case KnownManagedType.JSObject when jsType == JSTypeFlags.Object: return new PrimitiveJSGenerator(MarshalerType.JSObject); - case KnownManagedType.String when jsType == JSTypeFlags.String: return new PrimitiveJSGenerator(MarshalerType.String); - case KnownManagedType.Object when jsType == JSTypeFlags.Any: return new PrimitiveJSGenerator(MarshalerType.Object); + case KnownManagedType.Boolean when jsType == JSTypeFlags.Boolean: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Boolean)); + case KnownManagedType.Byte when jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Char when jsType == JSTypeFlags.String: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Char)); + case KnownManagedType.Int16 when jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Int16)); + case KnownManagedType.Int32 when jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Int32)); + case KnownManagedType.Int64 when jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Int52)); + case KnownManagedType.Int64 when jsType == JSTypeFlags.BigInt: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.BigInt64)); + case KnownManagedType.Single when jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Single)); + case KnownManagedType.Double when jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Double)); + case KnownManagedType.IntPtr when jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.IntPtr)); + case KnownManagedType.DateTime when jsType == JSTypeFlags.Date: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.DateTime)); + case KnownManagedType.DateTimeOffset when jsType == JSTypeFlags.Date: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.DateTimeOffset)); + case KnownManagedType.Exception when jsType == JSTypeFlags.Error: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Exception)); + case KnownManagedType.JSObject when jsType == JSTypeFlags.Object: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.JSObject)); + case KnownManagedType.String when jsType == JSTypeFlags.String: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.String)); + case KnownManagedType.Object when jsType == JSTypeFlags.Any: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Object)); // primitive missing - case KnownManagedType.Boolean when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.Boolean); - case KnownManagedType.Byte when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.Byte); - case KnownManagedType.Char when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.Char); - case KnownManagedType.Int16 when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.Int16); - case KnownManagedType.Int32 when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.Int32); - case KnownManagedType.Single when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.Single); - case KnownManagedType.Double when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.Double); - case KnownManagedType.IntPtr when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.IntPtr); - case KnownManagedType.Exception when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.Exception); - case KnownManagedType.JSObject when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.JSObject); - case KnownManagedType.String when jsType == JSTypeFlags.Missing: return new PrimitiveJSGenerator(MarshalerType.String); + case KnownManagedType.Boolean when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Boolean)); + case KnownManagedType.Byte when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Char when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Char)); + case KnownManagedType.Int16 when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Int16)); + case KnownManagedType.Int32 when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Int32)); + case KnownManagedType.Single when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Single)); + case KnownManagedType.Double when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Double)); + case KnownManagedType.IntPtr when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.IntPtr)); + case KnownManagedType.Exception when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.Exception)); + case KnownManagedType.JSObject when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.JSObject)); + case KnownManagedType.String when jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new PrimitiveJSGenerator(MarshalerType.String)); // primitive forced case KnownManagedType.Int64 when jsType == JSTypeFlags.Missing: case KnownManagedType.DateTime when jsType == JSTypeFlags.Missing: case KnownManagedType.DateTimeOffset when jsType == JSTypeFlags.Missing: case KnownManagedType.Object when jsType == JSTypeFlags.Missing: - throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); // nullable - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Boolean && jsType == JSTypeFlags.Boolean: return new NullableJSGenerator(MarshalerType.Boolean); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Number: return new NullableJSGenerator(MarshalerType.Byte); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Char && jsType == JSTypeFlags.String: return new NullableJSGenerator(MarshalerType.Byte); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int16 && jsType == JSTypeFlags.Number: return new NullableJSGenerator(MarshalerType.Int16); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Number: return new NullableJSGenerator(MarshalerType.Int32); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int64 && jsType == JSTypeFlags.Number: return new NullableJSGenerator(MarshalerType.Int52); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int64 && jsType == JSTypeFlags.BigInt: return new NullableJSGenerator(MarshalerType.BigInt64); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Number: return new NullableJSGenerator(MarshalerType.Double); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Single && jsType == JSTypeFlags.Number: return new NullableJSGenerator(MarshalerType.Single); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.IntPtr && jsType == JSTypeFlags.Number: return new NullableJSGenerator(MarshalerType.IntPtr); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.DateTime && jsType == JSTypeFlags.Date: return new NullableJSGenerator(MarshalerType.DateTime); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.DateTimeOffset && jsType == JSTypeFlags.Date: return new NullableJSGenerator(MarshalerType.DateTimeOffset); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Boolean && jsType == JSTypeFlags.Boolean: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Boolean)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Char && jsType == JSTypeFlags.String: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int16 && jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Int16)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Int32)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int64 && jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Int52)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int64 && jsType == JSTypeFlags.BigInt: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.BigInt64)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Double)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Single && jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Single)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.IntPtr && jsType == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.IntPtr)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.DateTime && jsType == JSTypeFlags.Date: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.DateTime)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.DateTimeOffset && jsType == JSTypeFlags.Date: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.DateTimeOffset)); // nullable missing - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Boolean && jsType == JSTypeFlags.Missing: return new NullableJSGenerator(MarshalerType.Boolean); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing: return new NullableJSGenerator(MarshalerType.Byte); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Char && jsType == JSTypeFlags.Missing: return new NullableJSGenerator(MarshalerType.Byte); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int16 && jsType == JSTypeFlags.Missing: return new NullableJSGenerator(MarshalerType.Int16); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing: return new NullableJSGenerator(MarshalerType.Int32); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Single && jsType == JSTypeFlags.Missing: return new NullableJSGenerator(MarshalerType.Single); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing: return new NullableJSGenerator(MarshalerType.Double); - case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.IntPtr && jsType == JSTypeFlags.Missing: return new NullableJSGenerator(MarshalerType.IntPtr); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Boolean && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Boolean)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Char && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int16 && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Int16)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Int32)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Single && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Single)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.Double)); + case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.IntPtr && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new NullableJSGenerator(MarshalerType.IntPtr)); // nullable forced case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.Int64 && jsType == JSTypeFlags.Missing: case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.DateTime && jsType == JSTypeFlags.Missing: case KnownManagedType.Nullable when argumentTypes[0] == KnownManagedType.DateTimeOffset && jsType == JSTypeFlags.Missing: - throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); case KnownManagedType.Nullable: - throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); // task - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes.Length == 0 && jsTypeArguments[0] == JSTypeFlags.Void: return new TaskJSGenerator(MarshalerType.Void); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Byte && jsTypeArguments[0] == JSTypeFlags.Number: return new TaskJSGenerator(MarshalerType.Byte); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Boolean && jsTypeArguments[0] == JSTypeFlags.Boolean: return new TaskJSGenerator(MarshalerType.Boolean); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Char && jsTypeArguments[0] == JSTypeFlags.String: return new TaskJSGenerator(MarshalerType.Char); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int16 && jsTypeArguments[0] == JSTypeFlags.Number: return new TaskJSGenerator(MarshalerType.Int16); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int32 && jsTypeArguments[0] == JSTypeFlags.Number: return new TaskJSGenerator(MarshalerType.Int32); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int64 && jsTypeArguments[0] == JSTypeFlags.Number: return new TaskJSGenerator(MarshalerType.Int52); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int64 && jsTypeArguments[0] == JSTypeFlags.BigInt: return new TaskJSGenerator(MarshalerType.BigInt64); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.IntPtr && jsTypeArguments[0] == JSTypeFlags.Number: return new TaskJSGenerator(MarshalerType.IntPtr); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Double && jsTypeArguments[0] == JSTypeFlags.Number: return new TaskJSGenerator(MarshalerType.Double); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Single && jsTypeArguments[0] == JSTypeFlags.Number: return new TaskJSGenerator(MarshalerType.Single); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.JSObject && jsTypeArguments[0] == JSTypeFlags.Object: return new TaskJSGenerator(MarshalerType.JSObject); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.String && jsTypeArguments[0] == JSTypeFlags.String: return new TaskJSGenerator(MarshalerType.String); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Exception && jsTypeArguments[0] == JSTypeFlags.Error: return new TaskJSGenerator(MarshalerType.Exception); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.DateTime && jsTypeArguments[0] == JSTypeFlags.Date: return new TaskJSGenerator(MarshalerType.DateTime); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.DateTimeOffset && jsTypeArguments[0] == JSTypeFlags.Date: return new TaskJSGenerator(MarshalerType.DateTimeOffset); - case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Object && jsTypeArguments[0] == JSTypeFlags.Any: return new TaskJSGenerator(MarshalerType.Object); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes.Length == 0 && jsTypeArguments[0] == JSTypeFlags.Void: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Void)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Byte && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Boolean && jsTypeArguments[0] == JSTypeFlags.Boolean: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Boolean)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Char && jsTypeArguments[0] == JSTypeFlags.String: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Char)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int16 && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Int16)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int32 && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Int32)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int64 && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Int52)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int64 && jsTypeArguments[0] == JSTypeFlags.BigInt: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.BigInt64)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.IntPtr && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.IntPtr)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Double && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Double)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Single && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Single)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.JSObject && jsTypeArguments[0] == JSTypeFlags.Object: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.JSObject)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.String && jsTypeArguments[0] == JSTypeFlags.String: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.String)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Exception && jsTypeArguments[0] == JSTypeFlags.Error: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Exception)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.DateTime && jsTypeArguments[0] == JSTypeFlags.Date: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.DateTime)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.DateTimeOffset && jsTypeArguments[0] == JSTypeFlags.Date: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.DateTimeOffset)); + case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Object && jsTypeArguments[0] == JSTypeFlags.Any: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Object)); // task missing - case KnownManagedType.Task when jsType == JSTypeFlags.Missing && argumentTypes.Length == 0: return new TaskJSGenerator(MarshalerType.Void); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Boolean && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.Boolean); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.Byte); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Char && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.Char); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Int16 && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.Int16); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.Int32); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Single && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.Single); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.Double); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.IntPtr && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.IntPtr); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.JSObject && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.JSObject); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.String && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.String); - case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Exception && jsType == JSTypeFlags.Missing: return new TaskJSGenerator(MarshalerType.Exception); + case KnownManagedType.Task when jsType == JSTypeFlags.Missing && argumentTypes.Length == 0: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Void)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Boolean && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Boolean)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Char && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Char)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Int16 && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Int16)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Int32)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Single && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Single)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Double)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.IntPtr && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.IntPtr)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.JSObject && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.JSObject)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.String && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.String)); + case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Exception && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new TaskJSGenerator(MarshalerType.Exception)); // task forced case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Int64 && jsType == JSTypeFlags.Missing: case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.DateTime && jsType == JSTypeFlags.Missing: case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.DateTimeOffset && jsType == JSTypeFlags.Missing: case KnownManagedType.Task when argumentTypes[0] == KnownManagedType.Object && jsType == JSTypeFlags.Missing: - throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); case KnownManagedType.Task when jsType == JSTypeFlags.Promise && jsTypeArguments.Length == 1: - throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); // array - case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Byte && jsTypeArguments[0] == JSTypeFlags.Number: return new ArrayJSGenerator(MarshalerType.Byte); - case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.String && jsTypeArguments[0] == JSTypeFlags.String: return new ArrayJSGenerator(MarshalerType.String); - case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Double && jsTypeArguments[0] == JSTypeFlags.Number: return new ArrayJSGenerator(MarshalerType.Double); - case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int32 && jsTypeArguments[0] == JSTypeFlags.Number: return new ArrayJSGenerator(MarshalerType.Int32); - case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.JSObject && jsTypeArguments[0] == JSTypeFlags.Object: return new ArrayJSGenerator(MarshalerType.JSObject); - case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Object && jsTypeArguments[0] == JSTypeFlags.Any: return new ArrayJSGenerator(MarshalerType.Object); + case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Byte && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.String && jsTypeArguments[0] == JSTypeFlags.String: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.String)); + case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Double && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.Double)); + case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Int32 && jsTypeArguments[0] == JSTypeFlags.Number: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.Int32)); + case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.JSObject && jsTypeArguments[0] == JSTypeFlags.Object: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.JSObject)); + case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1 && argumentTypes[0] == KnownManagedType.Object && jsTypeArguments[0] == JSTypeFlags.Any: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.Object)); // array missing - case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing: return new ArrayJSGenerator(MarshalerType.Byte); - case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.String && jsType == JSTypeFlags.Missing: return new ArrayJSGenerator(MarshalerType.String); - case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing: return new ArrayJSGenerator(MarshalerType.Double); - case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing: return new ArrayJSGenerator(MarshalerType.Int32); - case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.JSObject && jsType == JSTypeFlags.Missing: return new ArrayJSGenerator(MarshalerType.JSObject); + case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.String && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.String)); + case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.Double)); + case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.Int32)); + case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.JSObject && jsType == JSTypeFlags.Missing: return ResolvedGenerator.Resolved(new ArrayJSGenerator(MarshalerType.JSObject)); case KnownManagedType.Array when jsType == JSTypeFlags.Array && jsTypeArguments.Length == 1: - throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); // array forced case KnownManagedType.Array when argumentTypes[0] == KnownManagedType.Object && jsType == JSTypeFlags.Missing: - throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); // span view case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView && jsTypeArguments.Length != 0: - throw failWithReason(null); - case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Byte: return new SpanJSGenerator(MarshalerType.Byte); - case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Int32: return new SpanJSGenerator(MarshalerType.Int32); - case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Double: return new SpanJSGenerator(MarshalerType.Double); + return failWithReason(null); + case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Byte: return ResolvedGenerator.Resolved(new SpanJSGenerator(MarshalerType.Byte)); + case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Int32: return ResolvedGenerator.Resolved(new SpanJSGenerator(MarshalerType.Int32)); + case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Double: return ResolvedGenerator.Resolved(new SpanJSGenerator(MarshalerType.Double)); case KnownManagedType.Span when jsType == JSTypeFlags.MemoryView: - throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); // span forced case KnownManagedType.Span when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing: case KnownManagedType.Span when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing: case KnownManagedType.Span when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing: - throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); // segment view case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && jsTypeArguments.Length != 0: - throw failWithReason(null); - case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Byte: return new ArraySegmentJSGenerator(MarshalerType.Byte); - case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Int32: return new ArraySegmentJSGenerator(MarshalerType.Int32); - case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Double: return new ArraySegmentJSGenerator(MarshalerType.Double); + return failWithReason(null); + case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Byte: return ResolvedGenerator.Resolved(new ArraySegmentJSGenerator(MarshalerType.Byte)); + case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Int32: return ResolvedGenerator.Resolved(new ArraySegmentJSGenerator(MarshalerType.Int32)); + case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView && argumentTypes[0] == KnownManagedType.Double: return ResolvedGenerator.Resolved(new ArraySegmentJSGenerator(MarshalerType.Double)); case KnownManagedType.ArraySegment when jsType == JSTypeFlags.MemoryView: - throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); // segment forced case KnownManagedType.ArraySegment when argumentTypes[0] == KnownManagedType.Byte && jsType == JSTypeFlags.Missing: case KnownManagedType.ArraySegment when argumentTypes[0] == KnownManagedType.Int32 && jsType == JSTypeFlags.Missing: case KnownManagedType.ArraySegment when argumentTypes[0] == KnownManagedType.Double && jsType == JSTypeFlags.Missing: - throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); // function + action case KnownManagedType.Function when jsType == JSTypeFlags.Function && jsTypeArguments.Length == argumentTypes.Length: @@ -273,15 +273,21 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known || argumentTypes[i] == KnownManagedType.Unknown ) { - throw failWithReason(SR.Format(SR.FuncArgumentNotSupported, argumentTypes[i])); + return failWithReason(SR.Format(SR.FuncArgumentNotSupported, argumentTypes[i])); } var gen = Create(info, isToJs ^ (!isReturn), argumentTypes[i], Array.Empty(), jsTypeArguments[i], Array.Empty(), failWithReason); - argsMarshalers.Add(gen.Type); + argsMarshalers.Add(((BaseJSGenerator)gen.Generator).Type); } - return new FuncJSGenerator(marshaledType == KnownManagedType.Action, argsMarshalers.ToArray()); + var maxArgs = marshaledType == KnownManagedType.Action ? 3 : 4; + var argsMarshallerTypes = argsMarshalers.ToArray(); + if (argsMarshallerTypes.Length > maxArgs) + { + return failWithReason(SR.FuncTooManyArgs); + } + return ResolvedGenerator.Resolved(new FuncJSGenerator(marshaledType == KnownManagedType.Action, argsMarshallerTypes)); case KnownManagedType.Action when jsType == JSTypeFlags.Function: case KnownManagedType.Function when jsType == JSTypeFlags.Function: - throw failWithReason(SR.FuncWrongArgumentCount); + return failWithReason(SR.FuncWrongArgumentCount); // function + action forced case KnownManagedType.Function when jsType == JSTypeFlags.Missing: @@ -297,13 +303,13 @@ internal static BaseJSGenerator Create(TypePositionInfo info, bool isToJs, Known || argumentTypes[i] == KnownManagedType.Unknown ) { - throw failWithReason(SR.Format(SR.FuncArgumentNotSupported, argumentTypes[i])); + return failWithReason(SR.Format(SR.FuncArgumentNotSupported, argumentTypes[i])); } } - throw failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.UseJSMarshalAsAttribute, info.ManagedType.FullTypeName)); default: - throw failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); + return failWithReason(SR.Format(SR.TypeNotSupportedName, info.ManagedType.FullTypeName)); } } } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportCodeGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportCodeGenerator.cs index 7fbc4dd6ae9c84..946077fae2c3be 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportCodeGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportCodeGenerator.cs @@ -32,11 +32,9 @@ public JSImportCodeGenerator( ImmutableArray argTypes, JSImportData attributeData, JSSignatureContext signatureContext, - Action marshallingNotSupportedCallback, + Action marshallingNotSupportedCallback, IMarshallingGeneratorFactory generatorFactory) { - Action extendedInvariantViolationsCallback = (info, details) => - marshallingNotSupportedCallback(info, new MarshallingNotSupportedException(info, _context) { NotSupportedDetails = details }); _signatureContext = signatureContext; ManagedToNativeStubCodeContext innerContext = new ManagedToNativeStubCodeContext(targetFramework, targetFrameworkVersion, ReturnIdentifier, ReturnIdentifier); _context = new JSImportCodeContext(attributeData, innerContext); @@ -44,7 +42,7 @@ public JSImportCodeGenerator( foreach (var failure in bindingFailures) { - marshallingNotSupportedCallback(failure.Info, failure.Exception); + marshallingNotSupportedCallback(failure); } if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, null)) { @@ -59,7 +57,7 @@ public JSImportCodeGenerator( BoundGenerator spanArg = _marshallers.SignatureMarshallers.FirstOrDefault(m => m.TypeInfo.MarshallingAttributeInfo is JSMarshallingInfo(_, JSSpanTypeInfo)); if (spanArg != default) { - marshallingNotSupportedCallback(spanArg.TypeInfo, new MarshallingNotSupportedException(spanArg.TypeInfo, _context) + marshallingNotSupportedCallback(new GeneratorDiagnostic.NotSupported(spanArg.TypeInfo, _context) { NotSupportedDetails = SR.SpanAndTaskNotSupported }); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs index 32214ca1b7aa25..6a16632745011d 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs @@ -177,19 +177,22 @@ private static IncrementalStubGenerationContext CalculateStubInformation( Debug.Assert(jsImportAttr is not null); - var generatorDiagnostics = new GeneratorDiagnostics(); + var generatorDiagnostics = new GeneratorDiagnosticBag(); + var descriptorProvider = new DescriptorProvider(); // Process the JSImport attribute JSImportData? jsImportData = ProcessJSImportAttribute(jsImportAttr!); if (jsImportData is null) { - generatorDiagnostics.ReportConfigurationNotSupported(jsImportAttr!, "Invalid syntax"); + generatorDiagnostics.ReportConfigurationNotSupported(descriptorProvider, jsImportAttr!, "Invalid syntax"); jsImportData = new JSImportData("INVALID_CSHARP_SYNTAX", null); } // Create the stub. - var signatureContext = JSSignatureContext.Create(symbol, environment, generatorDiagnostics, ct); + + var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(descriptorProvider, generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); + var signatureContext = JSSignatureContext.Create(symbol, environment, marshallingInfoParserDiagnosticBag, ct); var containingTypeContext = new ContainingSyntaxContext(originalSyntax); @@ -214,7 +217,8 @@ private static IncrementalStubGenerationContext CalculateStubInformation( private static (MemberDeclarationSyntax, ImmutableArray) GenerateSource( IncrementalStubGenerationContext incrementalContext) { - var diagnostics = new GeneratorDiagnostics(); + var diagnostics = new GeneratorDiagnosticBag(); + var descriptorProvider = new DescriptorProvider(); // Generate stub code var stubGenerator = new JSImportCodeGenerator( @@ -223,9 +227,9 @@ private static (MemberDeclarationSyntax, ImmutableArray) Generat incrementalContext.SignatureContext.SignatureContext.ElementTypeInformation, incrementalContext.JSImportData, incrementalContext.SignatureContext, - (elementInfo, ex) => + ex => { - diagnostics.ReportMarshallingNotSupported(incrementalContext.DiagnosticLocation, elementInfo, ex.NotSupportedDetails, ex.DiagnosticProperties ?? ImmutableDictionary.Empty); + diagnostics.ReportGeneratorDiagnostic(descriptorProvider, incrementalContext.DiagnosticLocation, ex); }, incrementalContext.GeneratorFactoryKey.GeneratorFactory); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSSignatureContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSSignatureContext.cs index 8f2922099dc623..54f839b517b1f7 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSSignatureContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSSignatureContext.cs @@ -29,7 +29,7 @@ internal sealed record JSSignatureContext public static JSSignatureContext Create( IMethodSymbol method, StubEnvironment env, - GeneratorDiagnostics diagnostics, + MarshallingInfoParserDiagnosticsBag diagnostics, CancellationToken token) { // Cancel early if requested diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/FuncJSGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/FuncJSGenerator.cs index e1d1a4de81ac77..b70986a9b3afac 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/FuncJSGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/FuncJSGenerator.cs @@ -31,15 +31,6 @@ public override IEnumerable GenerateBind(TypePositionInfo info public override IEnumerable Generate(TypePositionInfo info, StubCodeContext context) { - var maxArgs = _isAction ? 3 : 4; - if (_argumentMarshalerTypes.Length > maxArgs) - { - throw new MarshallingNotSupportedException(info, context) - { - NotSupportedDetails = SR.FuncTooManyArgs - }; - } - string argName = context.GetAdditionalIdentifier(info, "js_arg"); var target = info.IsManagedReturnPosition ? Constants.ArgumentReturn diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs index ca45742c673575..b183b32d970da9 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs @@ -74,18 +74,19 @@ public override void Initialize(AnalysisContext context) // Use the method signature to do some of the work the generator will do after conversion. // If any diagnostics or failures to marshal are reported, then mark this diagnostic with a property signifying that it may require // later user work. - AnyDiagnosticsSink diagnostics = new(); + GeneratorDiagnosticBag diagnostics = new(); + MarshallingInfoParserDiagnosticsBag parserDiagnostics = new(new DiagnosticDescriptorProvider(), diagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); AttributeData comImportAttribute = type.GetAttributes().First(attr => attr.AttributeClass.ToDisplayString() == TypeNames.System_Runtime_InteropServices_ComImportAttribute); SignatureContext targetSignatureContext = SignatureContext.Create( method, - CreateComImportMarshallingInfoParser(env, diagnostics, method, comImportAttribute), + CreateComImportMarshallingInfoParser(env, parserDiagnostics, method, comImportAttribute), env, typeof(ConvertComImportToGeneratedComInterfaceAnalyzer).Assembly); var managedToUnmanagedFactory = ComInterfaceGeneratorHelpers.CreateGeneratorFactory(env, MarshalDirection.ManagedToUnmanaged); var unmanagedToManagedFactory = ComInterfaceGeneratorHelpers.CreateGeneratorFactory(env, MarshalDirection.UnmanagedToManaged); - mayRequireAdditionalWork = diagnostics.AnyDiagnostics; + mayRequireAdditionalWork = diagnostics.Diagnostics.Any(); bool anyExplicitlyUnsupportedInfo = false; var managedToNativeStubCodeContext = new ManagedToNativeStubCodeContext(env.TargetFramework, env.TargetFrameworkVersion, "return", "nativeReturn"); @@ -98,17 +99,17 @@ public override void Initialize(AnalysisContext context) if (s_unsupportedTypeNames.Contains(info.ManagedType.FullTypeName)) { anyExplicitlyUnsupportedInfo = true; - return forwarder; + return ResolvedGenerator.Resolved(forwarder); } if (HasUnsupportedMarshalAsInfo(info)) { anyExplicitlyUnsupportedInfo = true; - return forwarder; + return ResolvedGenerator.Resolved(forwarder); } if (info.MarshallingAttributeInfo is TrackedMarshallingInfo(TrackedMarshallingInfoAnnotation.ExplicitlyUnsupported, _)) { anyExplicitlyUnsupportedInfo = true; - return forwarder; + return ResolvedGenerator.Resolved(forwarder); } if (info.MarshallingAttributeInfo is TrackedMarshallingInfo(TrackedMarshallingInfoAnnotation annotation, var inner)) { @@ -119,11 +120,15 @@ public override void Initialize(AnalysisContext context) info = info with { MarshallingAttributeInfo = inner }; } // Run both factories and collect any binding failures. - _ = unmanagedToManagedFactory.GeneratorFactory.Create(info, nativeToManagedStubCodeContext); - return managedToUnmanagedFactory.GeneratorFactory.Create(info, managedToNativeStubCodeContext); - }), managedToNativeStubCodeContext, forwarder, out var bindingFailures); + ResolvedGenerator unmanagedToManagedGenerator = unmanagedToManagedFactory.GeneratorFactory.Create(info, nativeToManagedStubCodeContext); + ResolvedGenerator managedToUnmanagedGenerator = managedToUnmanagedFactory.GeneratorFactory.Create(info, managedToNativeStubCodeContext); + return managedToUnmanagedGenerator with + { + Diagnostics = managedToUnmanagedGenerator.Diagnostics.AddRange(unmanagedToManagedGenerator.Diagnostics) + }; + }), managedToNativeStubCodeContext, forwarder, out var generatorDiagnostics); - mayRequireAdditionalWork |= bindingFailures.Length > 0; + mayRequireAdditionalWork |= generatorDiagnostics.Any(diag => diag.IsFatal); if (anyExplicitlyUnsupportedInfo) { @@ -143,7 +148,7 @@ public override void Initialize(AnalysisContext context) }); } - private static MarshallingInfoParser CreateComImportMarshallingInfoParser(StubEnvironment env, IGeneratorDiagnostics diagnostics, IMethodSymbol method, AttributeData unparsedAttributeData) + private static MarshallingInfoParser CreateComImportMarshallingInfoParser(StubEnvironment env, MarshallingInfoParserDiagnosticsBag diagnostics, IMethodSymbol method, AttributeData unparsedAttributeData) { var defaultInfo = new DefaultMarshallingInfo(CharEncoding.Utf16, null); @@ -183,23 +188,16 @@ private static bool HasUnsupportedMarshalAsInfo(TypePositionInfo info) || unmanagedType == UnmanagedType.SafeArray; } - private sealed class AnyDiagnosticsSink : IGeneratorDiagnostics - { - public bool AnyDiagnostics { get; private set; } - public void ReportConfigurationNotSupported(AttributeData attributeData, string configurationName, string? unsupportedValue) => AnyDiagnostics = true; - public void ReportInvalidMarshallingAttributeInfo(AttributeData attributeData, string reasonResourceName, params string[] reasonArgs) => AnyDiagnostics = true; - } - private sealed class CallbackGeneratorFactory : IMarshallingGeneratorFactory { - private readonly Func _func; + private readonly Func _func; - public CallbackGeneratorFactory(Func func) + public CallbackGeneratorFactory(Func func) { _func = func; } - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) => _func(info, context); + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) => _func(info, context); } private enum TrackedMarshallingInfoAnnotation diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs index 4b25e4388939c3..2de38bf8ac080f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs @@ -235,22 +235,25 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M } } - var generatorDiagnostics = new GeneratorDiagnostics(); + var generatorDiagnostics = new GeneratorDiagnosticBag(); + var diagnosticDescriptors = new DiagnosticDescriptorProvider(); if (lcidConversionAttr is not null) { // Using LCIDConversion with source-generated interop is not supported - generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); + generatorDiagnostics.ReportConfigurationNotSupported(diagnosticDescriptors, lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } GeneratedComInterfaceCompilationData.TryGetGeneratedComInterfaceAttributeFromInterface(symbol.ContainingType, out var generatedComAttribute); var generatedComInterfaceAttributeData = GeneratedComInterfaceCompilationData.GetDataFromAttribute(generatedComAttribute); // Create the stub. + + var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(new DiagnosticDescriptorProvider(), generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); var signatureContext = SignatureContext.Create( symbol, DefaultMarshallingInfoParser.Create( environment, - generatorDiagnostics, + marshallingInfoParserDiagnosticBag, symbol, generatedComInterfaceAttributeData, generatedComAttribute), diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs new file mode 100644 index 00000000000000..478032194215d8 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs @@ -0,0 +1,30 @@ +// 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.Collections.Generic; +using System.Text; +using Microsoft.CodeAnalysis; + +namespace Microsoft.Interop +{ + internal sealed class DiagnosticDescriptorProvider : IDiagnosticDescriptorProvider + { + public DiagnosticDescriptor InvalidMarshallingAttributeInfo => GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported; + + public DiagnosticDescriptor GetConfigurationNotSupportedDescriptor(bool withValue) => withValue ? GeneratorDiagnostics.ConfigurationValueNotSupported : GeneratorDiagnostics.ConfigurationNotSupported; + + public DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic) + { + return diagnostic switch + { + GeneratorDiagnostic.NotSupported { NotSupportedDetails: null, TypePositionInfo: { IsManagedReturnPosition: true, MarshallingAttributeInfo: MarshalAsInfo } } => GeneratorDiagnostics.MarshalAsReturnConfigurationNotSupported, + GeneratorDiagnostic.NotSupported { NotSupportedDetails: null, TypePositionInfo: { IsManagedReturnPosition: false, MarshallingAttributeInfo: MarshalAsInfo } } => GeneratorDiagnostics.MarshalAsParameterConfigurationNotSupported, + GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, + GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, + { TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupported, + { TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupported, + }; + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs index 1944f4c28ba931..21052824695d35 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs @@ -11,7 +11,7 @@ namespace Microsoft.Interop /// /// Class for reporting diagnostics in the library import generator /// - public class GeneratorDiagnostics : IGeneratorDiagnostics + public static class GeneratorDiagnostics { public class Ids { @@ -206,6 +206,28 @@ public class Ids isEnabledByDefault: true, description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription))); + /// + public static readonly DiagnosticDescriptor MarshalAsParameterConfigurationNotSupported = + new DiagnosticDescriptor( + GeneratorDiagnostics.Ids.ConfigurationNotSupported, + GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)), + GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageParameter)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription))); + + /// + public static readonly DiagnosticDescriptor MarshalAsReturnConfigurationNotSupported = + new DiagnosticDescriptor( + GeneratorDiagnostics.Ids.ConfigurationNotSupported, + GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)), + GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageReturn)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription))); + /// public static readonly DiagnosticDescriptor ConfigurationNotSupported = new DiagnosticDescriptor( @@ -382,176 +404,42 @@ public class Ids isEnabledByDefault: true, description: GetResourceString(nameof(SR.ClassDoesNotImplementAnyGeneratedComInterfacesDescription))); - - private readonly List _diagnostics = new List(); - - public IEnumerable Diagnostics => _diagnostics; - - /// /// Report diagnostic for invalid configuration for string marshalling. /// /// Attribute specifying the invalid configuration /// Name of the method /// Specific reason the configuration is invalid - public void ReportInvalidStringMarshallingConfiguration( + public static void ReportInvalidStringMarshallingConfiguration( + this GeneratorDiagnosticBag diagnostics, AttributeData attributeData, string methodName, string detailsMessage) { - _diagnostics.Add( + diagnostics.ReportDiagnostic( attributeData.CreateDiagnosticInfo( GeneratorDiagnostics.InvalidStringMarshallingConfigurationOnMethod, methodName, detailsMessage)); } - /// /// Report diagnostic for invalid configuration for string marshalling. /// /// Attribute specifying the invalid configuration /// Name of the method /// Specific reason the configuration is invalid - public void ReportInvalidExceptionMarshallingConfiguration( + public static void ReportInvalidExceptionMarshallingConfiguration( + this GeneratorDiagnosticBag diagnostics, AttributeData attributeData, string methodName, string detailsMessage) { - _diagnostics.Add( + diagnostics.ReportDiagnostic( attributeData.CreateDiagnosticInfo( GeneratorDiagnostics.InvalidExceptionMarshallingConfiguration, methodName, detailsMessage)); } - - /// - /// Report diagnostic for configuration that is not supported by the DLL import source generator - /// - /// Attribute specifying the unsupported configuration - /// Name of the configuration - /// [Optiona] Unsupported configuration value - public void ReportConfigurationNotSupported( - AttributeData attributeData, - string configurationName, - string? unsupportedValue = null) - { - if (unsupportedValue == null) - { - _diagnostics.Add( - attributeData.CreateDiagnosticInfo( - GeneratorDiagnostics.ConfigurationNotSupported, - configurationName)); - } - else - { - _diagnostics.Add( - attributeData.CreateDiagnosticInfo( - GeneratorDiagnostics.ConfigurationValueNotSupported, - unsupportedValue, - configurationName)); - } - } - - /// - /// Report diagnostic for marshalling of a parameter/return that is not supported - /// - /// Method with the parameter/return - /// Type info for the parameter/return - /// [Optional] Specific reason for lack of support - public void ReportMarshallingNotSupported( - MethodSignatureDiagnosticLocations method, - TypePositionInfo info, - string? notSupportedDetails) - { - Location diagnosticLocation = CodeAnalysis.Location.None; - string elementName = string.Empty; - - if (info.IsManagedReturnPosition) - { - diagnosticLocation = method.FallbackLocation; - elementName = method.MethodIdentifier; - } - else - { - Debug.Assert(info.ManagedIndex <= method.ManagedParameterLocations.Length); - diagnosticLocation = method.ManagedParameterLocations[info.ManagedIndex]; - elementName = info.InstanceIdentifier; - } - - if (!string.IsNullOrEmpty(notSupportedDetails)) - { - // Report the specific not-supported reason. - if (info.IsManagedReturnPosition) - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, - notSupportedDetails!, - elementName)); - } - else - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, - notSupportedDetails!, - elementName)); - } - } - else if (info.MarshallingAttributeInfo is MarshalAsInfo) - { - // Report that the specified marshalling configuration is not supported. - // We don't forward marshalling attributes, so this is reported differently - // than when there is no attribute and the type itself is not supported. - if (info.IsManagedReturnPosition) - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ReturnConfigurationNotSupported, - nameof(System.Runtime.InteropServices.MarshalAsAttribute), - elementName)); - } - else - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ParameterConfigurationNotSupported, - nameof(System.Runtime.InteropServices.MarshalAsAttribute), - elementName)); - } - } - else - { - // Report that the type is not supported - if (info.IsManagedReturnPosition) - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ReturnTypeNotSupported, - info.ManagedType.DiagnosticFormattedName, - elementName)); - } - else - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ParameterTypeNotSupported, - info.ManagedType.DiagnosticFormattedName, - elementName)); - } - } - } - - public void ReportInvalidMarshallingAttributeInfo( - AttributeData attributeData, - string reasonResourceName, - params string[] reasonArgs) - { - _diagnostics.Add( - attributeData.CreateDiagnosticInfo( - GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported, - new LocalizableResourceString(reasonResourceName, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR), reasonArgs))); - } private static LocalizableResourceString GetResourceString(string resourceName) { return new LocalizableResourceString(resourceName, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ComInterfaceDispatchMarshallerFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ComInterfaceDispatchMarshallerFactory.cs index f44a442d1d5040..be71ae535f1c94 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ComInterfaceDispatchMarshallerFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ComInterfaceDispatchMarshallerFactory.cs @@ -22,8 +22,8 @@ public ComInterfaceDispatchMarshallerFactory(IMarshallingGeneratorFactory inner) _inner = inner; } - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) - => info.MarshallingAttributeInfo is ComInterfaceDispatchMarshallingInfo ? new Marshaller() : _inner.Create(info, context); + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) + => info.MarshallingAttributeInfo is ComInterfaceDispatchMarshallingInfo ? ResolvedGenerator.Resolved(new Marshaller()) : _inner.Create(info, context); private sealed class Marshaller : IMarshallingGenerator { diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ManagedHResultExceptionMarshallerFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ManagedHResultExceptionMarshallerFactory.cs index 0ab4edeeb20599..4c012042a05791 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ManagedHResultExceptionMarshallerFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ManagedHResultExceptionMarshallerFactory.cs @@ -27,16 +27,16 @@ public ManagedHResultExceptionMarshallerFactory(IMarshallingGeneratorFactory inn _direction = direction; } - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) { if (info.MarshallingAttributeInfo is ManagedHResultExceptionMarshallingInfo) { - return _direction switch + return ResolvedGenerator.Resolved(_direction switch { MarshalDirection.UnmanagedToManaged => new UnmanagedToManagedMarshaller(), MarshalDirection.ManagedToUnmanaged => new ManagedToUnmanagedMarshaller(), _ => throw new UnreachableException() - }; + }); } else { diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs index babd013163b8a5..b5a2d998890e8a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs @@ -20,8 +20,8 @@ public ObjectUnwrapperMarshallerFactory(IMarshallingGeneratorFactory inner) _inner = inner; } - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) - => info.MarshallingAttributeInfo is ObjectUnwrapperInfo ? new Marshaller() : _inner.Create(info, context); + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) + => info.MarshallingAttributeInfo is ObjectUnwrapperInfo ? ResolvedGenerator.Resolved(new Marshaller()) : _inner.Create(info, context); private sealed class Marshaller : IMarshallingGenerator { diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx index 576a94af4be3c1..d4415d46967ef5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx @@ -1,17 +1,17 @@  - @@ -377,4 +377,10 @@ Declaring an instance property in a type with the 'GeneratedComInterfaceAttribute' is not supported - + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf index 95ca798a74bc27..b0f93342ff3c3d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf @@ -327,6 +327,16 @@ Neplatné použití VirtualMethodIndexAttribute + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. Všechny metody musí být deklarované ve stejné částečné definici typu rozhraní GeneratedComInterface s atributy, aby se zajistil spolehlivý výpočet pro posuny tabulky virtuálních metod. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf index 33114ec03e8d87..f32c63a00b8feb 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf @@ -327,6 +327,16 @@ Ungültige Verwendung von „VirtualMethodIndexAttribute“ + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. Alle Methoden müssen in derselben partiellen Definition eines Schnittstellentyps mit Attributen vom Typ "GeneratedComInterface" deklariert werden, um eine zuverlässige Berechnung für Tabellenoffsets virtueller Methoden sicherzustellen. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf index 4442d7323fc7ac..e83fc331d17ebd 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf @@ -327,6 +327,16 @@ Uso de ”VirtualMethodIndexAttribute” no válido + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. Todos los métodos deben declararse en la misma definición parcial de un tipo de interfaz con atributos "GeneratedComInterface" para garantizar un cálculo confiable de los desplazamientos de la tabla de métodos virtuales. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf index 15bbe002d172ec..364864c0b744d2 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf @@ -327,6 +327,16 @@ Utilisation de « VirtualMethodIndexAttribute » non valide + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. Toutes les méthodes doivent être déclarées dans la même définition partielle d’un type d’interface avec attribut « GeneratedComInterface » pour garantir un calcul fiable des décalages de table de méthodes virtuelles. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf index 29f4fe8bceb24b..c959def76d7fe5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf @@ -327,6 +327,16 @@ Utilizzo di 'VirtualMethodIndexAttribute' non valido + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. Tutti i metodi devono essere dichiarati nella stessa definizione parziale di un tipo di interfaccia con attributo 'GeneratedComInterface' per garantire un calcolo affidabile per gli offset della tabella dei metodi virtuali. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf index 276b247ecc43ea..d13b70aeaf2eb5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf @@ -327,6 +327,16 @@ 'VirtualMethodIndexAttribute' の使用法が無効です + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. 仮想メソッド テーブルのオフセットを確実に計算するには、'GeneratedComInterface' 属性インターフェイスの種類の同じ部分定義で、すべてのメソッドを宣言する必要があります。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf index dfc150a76a8121..5e2b8aacb955a5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf @@ -327,6 +327,16 @@ 잘못된 'VirtualMethodIndexAttribute' 사용 + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. 모든 메서드는 가상 메서드 테이블 오프셋에 대한 신뢰할 수 있는 계산을 보장하기 위해 'GeneratedComInterface' 속성 인터페이스 유형의 동일한 부분 정의에서 선언되어야 합니다. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf index e6984574500e15..e15810496148e3 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf @@ -327,6 +327,16 @@ Nieprawidłowe użycie elementu "VirtualMethodIndexAttribute" + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. Wszystkie metody muszą być zadeklarowane w tej samej częściowej definicji przypisanego typu interfejsu „GeneratedComInterface” w celu zapewnienia niezawodnego obliczania przesunięć tabeli metod wirtualnych. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf index ec7e49de6fc816..decc9503922448 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf @@ -327,6 +327,16 @@ Uso inválido de 'VirtualMethodIndexAttribute' + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. Todos os métodos devem ser declarados na mesma definição parcial de um tipo de interface atribuído a "GeneratedComInterface" para garantir um cálculo confiável para deslocamentos de tabela de métodos virtuais. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf index 2dfaaffdd8bf32..1c76a73e522674 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf @@ -327,6 +327,16 @@ Недопустимое использование VirtualMethodIndexAttribute + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. Все методы должны быть объявлены в одном частичном определении типа интерфейса с атрибутом GeneratedComInterface, чтобы обеспечить надежное вычисление смещений таблицы виртуальных методов. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf index 80b64339cc073d..a28ab9f837a27a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf @@ -327,6 +327,16 @@ Geçersiz 'VirtualMethodIndexAttribute' kullanımı + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. Tüm yöntemler, sanal yöntem tablosu uzaklıkları için güvenilir hesaplamayı sağlamak amacıyla 'GeneratedComInterface' özniteliğine sahip arabirim türünün aynı kısmi tanımında bildirilmiş olmalıdır. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf index c3117112a8c39b..f169c4488a1b60 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf @@ -327,6 +327,16 @@ “VirtualMethodIndexAttribute” 使用情况无效 + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. 所有方法都必须在 “GeneratedComInterface” 特性化接口类型的同一部分定义中声明,以确保对虚拟方法表偏移进行可靠的计算。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf index 6634fc0681f8d0..7482968fceb6d0 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf @@ -327,6 +327,16 @@ 'VirtualMethodIndexAttribute' 使用方式無效 + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. + + All methods must be declared in the same partial definition of a 'GeneratedComInterface'-attributed interface type to ensure reliable calculation for virtual method table offsets. 所有方法都必須在 'GeneratedComInterface' 屬性化介面類型的相同部分定義中宣告,以確保對虛擬方法資料表位移進行可靠的計算。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnmanagedToManagedStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnmanagedToManagedStubGenerator.cs index 7acc249f96eff7..9038d96f291812 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnmanagedToManagedStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnmanagedToManagedStubGenerator.cs @@ -24,15 +24,15 @@ public UnmanagedToManagedStubGenerator( TargetFramework targetFramework, Version targetFrameworkVersion, ImmutableArray argTypes, - Action marshallingNotSupportedCallback, + Action marshallingNotSupportedCallback, IMarshallingGeneratorFactory generatorFactory) { _context = new NativeToManagedStubCodeContext(targetFramework, targetFrameworkVersion, ReturnIdentifier, ReturnIdentifier); - _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new Forwarder(), out var bindingFailures); + _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new Forwarder(), out var bindingDiagnostics); - foreach (var failure in bindingFailures) + foreach (var diagnostic in bindingDiagnostics) { - marshallingNotSupportedCallback(failure.Info, failure.Exception); + marshallingNotSupportedCallback(diagnostic); } if (_marshallers.NativeReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.NativeReturnMarshaller.TypeInfo, _context)) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs index f5a8a713db3d97..a3b9a07e12e992 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs @@ -18,7 +18,8 @@ internal static class VirtualMethodPointerStubGenerator public static (MethodDeclarationSyntax, ImmutableArray) GenerateManagedToNativeStub( IncrementalMethodStubGenerationContext methodStub) { - var diagnostics = new GeneratorDiagnostics(); + var diagnosticDescriptors = new DiagnosticDescriptorProvider(); + var diagnostics = new GeneratorDiagnosticBag(); // Generate stub code var stubGenerator = new ManagedToNativeVTableMethodGenerator( @@ -27,9 +28,9 @@ public static (MethodDeclarationSyntax, ImmutableArray) Generate methodStub.SignatureContext.ElementTypeInformation, methodStub.VtableIndexData.SetLastError, methodStub.VtableIndexData.ImplicitThisParameter, - (elementInfo, ex) => + ex => { - diagnostics.ReportMarshallingNotSupported(methodStub.DiagnosticLocation, elementInfo, ex.NotSupportedDetails); + diagnostics.ReportGeneratorDiagnostic(diagnosticDescriptors, methodStub.DiagnosticLocation, ex); }, methodStub.ManagedToUnmanagedGeneratorFactory.GeneratorFactory); @@ -68,7 +69,8 @@ private static MethodDeclarationSyntax PrintGeneratedSource( public static (MethodDeclarationSyntax, ImmutableArray) GenerateNativeToManagedStub( IncrementalMethodStubGenerationContext methodStub) { - var diagnostics = new GeneratorDiagnostics(); + var diagnosticDescriptors = new DiagnosticDescriptorProvider(); + var diagnostics = new GeneratorDiagnosticBag(); ImmutableArray elements = AddImplicitElementInfos(methodStub); // Generate stub code @@ -76,9 +78,9 @@ public static (MethodDeclarationSyntax, ImmutableArray) Generate methodStub.UnmanagedToManagedGeneratorFactory.Key.TargetFramework, methodStub.UnmanagedToManagedGeneratorFactory.Key.TargetFrameworkVersion, elements, - (elementInfo, ex) => + ex => { - diagnostics.ReportMarshallingNotSupported(methodStub.DiagnosticLocation, elementInfo, ex.NotSupportedDetails); + diagnostics.ReportGeneratorDiagnostic(diagnosticDescriptors, methodStub.DiagnosticLocation, ex); }, methodStub.UnmanagedToManagedGeneratorFactory.GeneratorFactory); @@ -179,7 +181,7 @@ private static FunctionPointerTypeSyntax GenerateUnmanagedFunctionPointerTypeFor method.UnmanagedToManagedGeneratorFactory.Key.TargetFrameworkVersion, AddImplicitElementInfos(method), // Swallow diagnostics here since the diagnostics will be reported by the unmanaged->managed stub generation - (elementInfo, ex) => { }, + diag => { }, method.UnmanagedToManagedGeneratorFactory.GeneratorFactory); List functionPointerParameters = new(); diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs index f674968c81f392..00aa31ed514303 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.Interop.Analyzers; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; [assembly: System.Resources.NeutralResourcesLanguage("en-US")] @@ -229,7 +230,8 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M Debug.Assert(virtualMethodIndexAttr is not null); - var generatorDiagnostics = new GeneratorDiagnostics(); + var generatorDiagnostics = new GeneratorDiagnosticBag(); + var descriptorProvider = new DiagnosticDescriptorProvider(); // Process the LibraryImport attribute VirtualMethodIndexCompilationData? virtualMethodIndexData = ProcessVirtualMethodIndexAttribute(virtualMethodIndexAttr!); @@ -268,11 +270,12 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M if (lcidConversionAttr is not null) { // Using LCIDConversion with source-generated interop is not supported - generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); + generatorDiagnostics.ReportConfigurationNotSupported(descriptorProvider, lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } // Create the stub. - var signatureContext = SignatureContext.Create(symbol, DefaultMarshallingInfoParser.Create(environment, generatorDiagnostics, symbol, virtualMethodIndexData, virtualMethodIndexAttr), environment, typeof(VtableIndexStubGenerator).Assembly); + var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(descriptorProvider, generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); + var signatureContext = SignatureContext.Create(symbol, DefaultMarshallingInfoParser.Create(environment, marshallingInfoParserDiagnosticBag, symbol, virtualMethodIndexData, virtualMethodIndexAttr), environment, typeof(VtableIndexStubGenerator).Assembly); var containingSyntaxContext = new ContainingSyntaxContext(syntax); @@ -315,7 +318,7 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M new ObjectUnwrapperInfo(unwrapperSyntax)); } - private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virtualMethodIndexAttr, ISymbol symbol, Compilation compilation, GeneratorDiagnostics diagnostics, VirtualMethodIndexCompilationData virtualMethodIndexData) + private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virtualMethodIndexAttr, ISymbol symbol, Compilation compilation, GeneratorDiagnosticBag diagnostics, VirtualMethodIndexCompilationData virtualMethodIndexData) { if (virtualMethodIndexData.ExceptionMarshallingDefined) { @@ -341,6 +344,7 @@ private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virt } if (virtualMethodIndexData.ExceptionMarshalling == ExceptionMarshalling.Custom) { + var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(new DiagnosticDescriptorProvider(), diagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); return virtualMethodIndexData.ExceptionMarshallingCustomType is null ? NoMarshallingInfo.Instance : CustomMarshallingInfoHelper.CreateNativeMarshallingInfoForNonSignatureElement( @@ -348,7 +352,7 @@ private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virt virtualMethodIndexData.ExceptionMarshallingCustomType!, virtualMethodIndexAttr, compilation, - diagnostics); + marshallingInfoParserDiagnosticBag); } // This should not be reached in normal usage, but a developer can cast any int to the ExceptionMarshalling enum, so we should handle this case without crashing the generator. diagnostics.ReportInvalidExceptionMarshallingConfiguration( diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/DefaultMarshallingInfoParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Common/DefaultMarshallingInfoParser.cs index 7149fc40a6f639..62b22f3ee112c7 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Common/DefaultMarshallingInfoParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Common/DefaultMarshallingInfoParser.cs @@ -8,7 +8,7 @@ namespace Microsoft.Interop { internal static class DefaultMarshallingInfoParser { - public static MarshallingInfoParser Create(StubEnvironment env, IGeneratorDiagnostics diagnostics, IMethodSymbol method, InteropAttributeCompilationData interopAttributeData, AttributeData unparsedAttributeData) + public static MarshallingInfoParser Create(StubEnvironment env, MarshallingInfoParserDiagnosticsBag diagnostics, IMethodSymbol method, InteropAttributeCompilationData interopAttributeData, AttributeData unparsedAttributeData) { // Compute the current default string encoding value. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs index 0789028403d9e8..4c94220dd2beb4 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs @@ -93,13 +93,14 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbo // Use the DllImport attribute data and the method signature to do some of the work the generator will do after conversion. // If any diagnostics or failures to marshal are reported, then mark this diagnostic with a property signifying that it may require // later user work. - AnyDiagnosticsSink diagnostics = new(); + GeneratorDiagnosticBag diagnostics = new(); + MarshallingInfoParserDiagnosticsBag parserDiagnostics = new(new DiagnosticDescriptorProvider(), diagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR)); AttributeData dllImportAttribute = method.GetAttributes().First(attr => attr.AttributeClass.ToDisplayString() == TypeNames.DllImportAttribute); - SignatureContext targetSignatureContext = SignatureContext.Create(method, DefaultMarshallingInfoParser.Create(env, diagnostics, method, CreateInteropAttributeDataFromDllImport(dllImportData), dllImportAttribute), env, typeof(ConvertToLibraryImportAnalyzer).Assembly); + SignatureContext targetSignatureContext = SignatureContext.Create(method, DefaultMarshallingInfoParser.Create(env, parserDiagnostics, method, CreateInteropAttributeDataFromDllImport(dllImportData), dllImportAttribute), env, typeof(ConvertToLibraryImportAnalyzer).Assembly); var generatorFactoryKey = LibraryImportGeneratorHelpers.CreateGeneratorFactory(env, new LibraryImportGeneratorOptions(context.Options.AnalyzerConfigOptionsProvider.GlobalOptions)); - bool mayRequireAdditionalWork = diagnostics.AnyDiagnostics; + bool mayRequireAdditionalWork = diagnostics.Diagnostics.Any(); bool anyExplicitlyUnsupportedInfo = false; var stubCodeContext = new ManagedToNativeStubCodeContext(env.TargetFramework, env.TargetFrameworkVersion, "return", "nativeReturn"); @@ -111,17 +112,17 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbo if (s_unsupportedTypeNames.Contains(info.ManagedType.FullTypeName)) { anyExplicitlyUnsupportedInfo = true; - return forwarder; + return ResolvedGenerator.Resolved(forwarder); } if (HasUnsupportedMarshalAsInfo(info)) { anyExplicitlyUnsupportedInfo = true; - return forwarder; + return ResolvedGenerator.Resolved(forwarder); } return generatorFactoryKey.GeneratorFactory.Create(info, stubCodeContext); }), stubCodeContext, forwarder, out var bindingFailures); - mayRequireAdditionalWork |= bindingFailures.Length > 0; + mayRequireAdditionalWork |= bindingFailures.Any(d => d.IsFatal); if (anyExplicitlyUnsupportedInfo) { @@ -168,23 +169,16 @@ private static InteropAttributeCompilationData CreateInteropAttributeDataFromDll return interopData; } - private sealed class AnyDiagnosticsSink : IGeneratorDiagnostics - { - public bool AnyDiagnostics { get; private set; } - public void ReportConfigurationNotSupported(AttributeData attributeData, string configurationName, string? unsupportedValue) => AnyDiagnostics = true; - public void ReportInvalidMarshallingAttributeInfo(AttributeData attributeData, string reasonResourceName, params string[] reasonArgs) => AnyDiagnostics = true; - } - private sealed class CallbackGeneratorFactory : IMarshallingGeneratorFactory { - private readonly Func _func; + private readonly Func _func; - public CallbackGeneratorFactory(Func func) + public CallbackGeneratorFactory(Func func) { _func = func; } - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) => _func(info, context); + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) => _func(info, context); } } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs new file mode 100644 index 00000000000000..df03fe7aeba34e --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs @@ -0,0 +1,28 @@ +// 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 Microsoft.CodeAnalysis; + +namespace Microsoft.Interop +{ + internal sealed class DiagnosticDescriptorProvider : IDiagnosticDescriptorProvider + { + public DiagnosticDescriptor InvalidMarshallingAttributeInfo => GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported; + + public DiagnosticDescriptor GetConfigurationNotSupportedDescriptor(bool withValue) => withValue ? GeneratorDiagnostics.ConfigurationValueNotSupported : GeneratorDiagnostics.ConfigurationNotSupported; + + public DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic) + { + return diagnostic switch + { + GeneratorDiagnostic.NotSupported { NotSupportedDetails: null, TypePositionInfo: { IsManagedReturnPosition: true, MarshallingAttributeInfo: MarshalAsInfo } } => GeneratorDiagnostics.MarshalAsReturnConfigurationNotSupported, + GeneratorDiagnostic.NotSupported { NotSupportedDetails: null, TypePositionInfo: { IsManagedReturnPosition: false, MarshallingAttributeInfo: MarshalAsInfo } } => GeneratorDiagnostics.MarshalAsParameterConfigurationNotSupported, + GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, + GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, + { TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupported, + { TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupported, + }; + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/ForwarderMarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/ForwarderMarshallingGeneratorFactory.cs index c8f339f372cb4d..4247d5eb021e77 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/ForwarderMarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/ForwarderMarshallingGeneratorFactory.cs @@ -11,6 +11,6 @@ internal sealed class ForwarderMarshallingGeneratorFactory : IMarshallingGenerat { private static readonly Forwarder s_forwarder = new Forwarder(); - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) => s_forwarder; + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) => ResolvedGenerator.Resolved(s_forwarder); } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs index 491c79939bd759..ad59c12d1b9de6 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs @@ -12,7 +12,7 @@ namespace Microsoft.Interop /// /// Class for reporting diagnostics in the library import generator /// - public class GeneratorDiagnostics : IGeneratorDiagnostics + public static class GeneratorDiagnostics { public class Ids { @@ -118,6 +118,26 @@ public class Ids isEnabledByDefault: true, description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription))); + public static readonly DiagnosticDescriptor MarshalAsParameterConfigurationNotSupported = + new DiagnosticDescriptor( + GeneratorDiagnostics.Ids.ConfigurationNotSupported, + GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)), + GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageParameter)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription))); + + public static readonly DiagnosticDescriptor MarshalAsReturnConfigurationNotSupported = + new DiagnosticDescriptor( + GeneratorDiagnostics.Ids.ConfigurationNotSupported, + GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)), + GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageReturn)), + Category, + DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription))); + public static readonly DiagnosticDescriptor ConfigurationNotSupported = new DiagnosticDescriptor( Ids.ConfigurationNotSupported, @@ -168,173 +188,34 @@ public class Ids isEnabledByDefault: true, description: GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksDescription))); - private readonly List _diagnostics = new List(); - - public IEnumerable Diagnostics => _diagnostics; - /// /// Report diagnostic for invalid configuration for string marshalling. /// /// Attribute specifying the invalid configuration /// Name of the method /// Specific reason the configuration is invalid - public void ReportInvalidStringMarshallingConfiguration( + public static void ReportInvalidStringMarshallingConfiguration( + this GeneratorDiagnosticBag diagnostics, AttributeData attributeData, string methodName, string detailsMessage) { - _diagnostics.Add( + diagnostics.ReportDiagnostic( attributeData.CreateDiagnosticInfo( GeneratorDiagnostics.InvalidStringMarshallingConfiguration, methodName, detailsMessage)); } - /// - /// Report diagnostic for configuration that is not supported by the DLL import source generator - /// - /// Attribute specifying the unsupported configuration - /// Name of the configuration - /// [Optiona] Unsupported configuration value - public void ReportConfigurationNotSupported( - AttributeData attributeData, - string configurationName, - string? unsupportedValue = null) - { - if (unsupportedValue == null) - { - _diagnostics.Add( - attributeData.CreateDiagnosticInfo( - GeneratorDiagnostics.ConfigurationNotSupported, - configurationName)); - } - else - { - _diagnostics.Add( - attributeData.CreateDiagnosticInfo( - GeneratorDiagnostics.ConfigurationValueNotSupported, - unsupportedValue, - configurationName)); - } - } - - /// - /// Report diagnostic for marshalling of a parameter/return that is not supported - /// - /// Method with the parameter/return - /// Type info for the parameter/return - /// [Optional] Specific reason for lack of support - public void ReportMarshallingNotSupported( - MethodSignatureDiagnosticLocations diagnosticLocations, - TypePositionInfo info, - string? notSupportedDetails, - ImmutableDictionary diagnosticProperties) - { - Location diagnosticLocation = Location.None; - string elementName = string.Empty; - - if (info.IsManagedReturnPosition) - { - diagnosticLocation = diagnosticLocations.FallbackLocation; - elementName = diagnosticLocations.MethodIdentifier; - } - else - { - Debug.Assert(info.ManagedIndex <= diagnosticLocations.ManagedParameterLocations.Length); - diagnosticLocation = diagnosticLocations.ManagedParameterLocations[info.ManagedIndex]; - elementName = info.InstanceIdentifier; - } - - if (!string.IsNullOrEmpty(notSupportedDetails)) - { - // Report the specific not-supported reason. - if (info.IsManagedReturnPosition) - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, - diagnosticProperties, - notSupportedDetails!, - elementName)); - } - else - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, - diagnosticProperties, - notSupportedDetails!, - elementName)); - } - } - else if (info.MarshallingAttributeInfo is MarshalAsInfo) - { - // Report that the specified marshalling configuration is not supported. - // We don't forward marshalling attributes, so this is reported differently - // than when there is no attribute and the type itself is not supported. - if (info.IsManagedReturnPosition) - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ReturnConfigurationNotSupported, - diagnosticProperties, - nameof(System.Runtime.InteropServices.MarshalAsAttribute), - elementName)); - } - else - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ParameterConfigurationNotSupported, - diagnosticProperties, - nameof(System.Runtime.InteropServices.MarshalAsAttribute), - elementName)); - } - } - else - { - // Report that the type is not supported - if (info.IsManagedReturnPosition) - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ReturnTypeNotSupported, - diagnosticProperties, - info.ManagedType.DiagnosticFormattedName, - elementName)); - } - else - { - _diagnostics.Add( - diagnosticLocation.CreateDiagnosticInfo( - GeneratorDiagnostics.ParameterTypeNotSupported, - diagnosticProperties, - info.ManagedType.DiagnosticFormattedName, - elementName)); - } - } - } - - public void ReportInvalidMarshallingAttributeInfo( - AttributeData attributeData, - string reasonResourceName, - params string[] reasonArgs) - { - _diagnostics.Add( - attributeData.CreateDiagnosticInfo( - GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported, - new LocalizableResourceString(reasonResourceName, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR), reasonArgs))); - } - /// /// Report diagnostic for configuration that cannot be forwarded to /// /// Method with the configuration that cannot be forwarded /// Configuration name /// Configuration value - public void ReportCannotForwardToDllImport(MethodSignatureDiagnosticLocations method, string name, string? value = null) + public static void ReportCannotForwardToDllImport(this GeneratorDiagnosticBag diagnostics, MethodSignatureDiagnosticLocations method, string name, string? value = null) { - _diagnostics.Add( + diagnostics.ReportDiagnostic( DiagnosticInfo.Create( CannotForwardToDllImport, method.FallbackLocation, diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs index 0018d92e7f532c..26d9e014e674cf 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs @@ -252,7 +252,8 @@ private static IncrementalStubGenerationContext CalculateStubInformation( Debug.Assert(generatedDllImportAttr is not null); - var generatorDiagnostics = new GeneratorDiagnostics(); + var generatorDiagnostics = new GeneratorDiagnosticBag(); + DiagnosticDescriptorProvider descriptorProvider = new(); // Process the LibraryImport attribute LibraryImportCompilationData libraryImportData = @@ -279,11 +280,12 @@ private static IncrementalStubGenerationContext CalculateStubInformation( if (lcidConversionAttr is not null) { // Using LCIDConversion with LibraryImport is not supported - generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); + generatorDiagnostics.ReportConfigurationNotSupported(descriptorProvider, lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } // Create the stub. - var signatureContext = SignatureContext.Create(symbol, DefaultMarshallingInfoParser.Create(environment, generatorDiagnostics, symbol, libraryImportData, generatedDllImportAttr), environment, typeof(LibraryImportGenerator).Assembly); + var marshallingInfoParserDiagnosticsBag = new MarshallingInfoParserDiagnosticsBag(descriptorProvider, generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR)); + var signatureContext = SignatureContext.Create(symbol, DefaultMarshallingInfoParser.Create(environment, marshallingInfoParserDiagnosticsBag, symbol, libraryImportData, generatedDllImportAttr), environment, typeof(LibraryImportGenerator).Assembly); var containingTypeContext = new ContainingSyntaxContext(originalSyntax); @@ -306,7 +308,8 @@ private static (MemberDeclarationSyntax, ImmutableArray) Generat IncrementalStubGenerationContext pinvokeStub, LibraryImportGeneratorOptions options) { - var diagnostics = new GeneratorDiagnostics(); + DiagnosticDescriptorProvider descriptorProvider = new(); + var diagnostics = new GeneratorDiagnosticBag(); if (options.GenerateForwarders) { return (PrintForwarderStub(pinvokeStub.StubMethodSyntaxTemplate, explicitForwarding: true, pinvokeStub, diagnostics), pinvokeStub.Diagnostics.Array.AddRange(diagnostics.Diagnostics)); @@ -318,10 +321,7 @@ private static (MemberDeclarationSyntax, ImmutableArray) Generat pinvokeStub.GeneratorFactoryKey.Key.Version, pinvokeStub.SignatureContext.ElementTypeInformation, pinvokeStub.LibraryImportData.SetLastError && !options.GenerateForwarders, - (elementInfo, ex) => - { - diagnostics.ReportMarshallingNotSupported(pinvokeStub.DiagnosticLocation, elementInfo, ex.NotSupportedDetails, ex.DiagnosticProperties ?? ImmutableDictionary.Empty); - }, + ex => diagnostics.ReportGeneratorDiagnostic(descriptorProvider, pinvokeStub.DiagnosticLocation, ex), pinvokeStub.GeneratorFactoryKey.GeneratorFactory); // Check if the generator should produce a forwarder stub - regular DllImport. @@ -356,7 +356,7 @@ private static (MemberDeclarationSyntax, ImmutableArray) Generat return (pinvokeStub.ContainingSyntaxContext.WrapMemberInContainingSyntaxWithUnsafeModifier(PrintGeneratedSource(pinvokeStub.StubMethodSyntaxTemplate, pinvokeStub.SignatureContext, code)), pinvokeStub.Diagnostics.Array.AddRange(diagnostics.Diagnostics)); } - private static MemberDeclarationSyntax PrintForwarderStub(ContainingSyntax userDeclaredMethod, bool explicitForwarding, IncrementalStubGenerationContext stub, GeneratorDiagnostics diagnostics) + private static MemberDeclarationSyntax PrintForwarderStub(ContainingSyntax userDeclaredMethod, bool explicitForwarding, IncrementalStubGenerationContext stub, GeneratorDiagnosticBag diagnostics) { LibraryImportData pinvokeData = stub.LibraryImportData with { EntryPoint = stub.LibraryImportData.EntryPoint ?? userDeclaredMethod.Identifier.ValueText }; diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs index 5019c3445af1ab..6476e228f20417 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs @@ -50,7 +50,7 @@ public PInvokeStubCodeGenerator( Version targetFrameworkVersion, ImmutableArray argTypes, bool setLastError, - Action marshallingNotSupportedCallback, + Action marshallingNotSupportedCallback, IMarshallingGeneratorFactory generatorFactory) { _setLastError = setLastError; @@ -68,11 +68,11 @@ public PInvokeStubCodeGenerator( } _context = new ManagedToNativeStubCodeContext(targetFramework, targetFrameworkVersion, ReturnIdentifier, ReturnIdentifier); - _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new Forwarder(), out var bindingFailures); + _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new Forwarder(), out var bindingDiagnostics); - foreach (var failure in bindingFailures) + foreach (var diagnostic in bindingDiagnostics) { - marshallingNotSupportedCallback(failure.Info, failure.Exception); + marshallingNotSupportedCallback(diagnostic); } if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, _context)) diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx index d05dd577c8b606..2d1d9fe9f69451 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx @@ -1,17 +1,17 @@  - @@ -503,4 +503,10 @@ The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. - + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.cs.xlf index b5212d6d007901..4021228a42f051 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.cs.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.cs.xlf @@ -317,6 +317,16 @@ Spravovaný typ pro zařazovací typ vstupního bodu {0} nesmí nabývat hodnoty null. + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.de.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.de.xlf index b4f25336b85c82..9ceb0c44ec2b98 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.de.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.de.xlf @@ -317,6 +317,16 @@ Der verwaltete Typ für den Einstiegspunkt-Marshallertyp "{0}" darf nicht "NULL" sein + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.es.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.es.xlf index 5cbbc2ee9a1306..0c2dc5c65975c1 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.es.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.es.xlf @@ -317,6 +317,16 @@ El tipo administrado para el tipo de serializador de punto de entrada "{0}" no debe ser "null" + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.fr.xlf index 1809d7ac02029d..51b110e8c7ea58 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.fr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.fr.xlf @@ -317,6 +317,16 @@ Le type managé du type marshaleur de point d’entrée « {0} » ne doit pas avoir la valeur 'null' + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.it.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.it.xlf index 28762e906cb414..9e7b077e2a2834 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.it.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.it.xlf @@ -317,6 +317,16 @@ Il tipo gestito per il tipo di marshaller del punto di ingresso '{0}' non deve essere 'null' + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. L'argomento 'marshalMode' di 'CustomMarshallerAttribute' deve essere un valore di enumerazione valido di 'MarshalMode'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ja.xlf index 5e5991961610cf..fea9c52f3a69bb 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ja.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ja.xlf @@ -317,6 +317,16 @@ エントリ ポイント マーシャラー型 '{0}' のマネージド型を 'null' にすることはできません + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. 'CustomMarshallerAttribute' の 'marshalMode' 引数は、'MarshalMode' の有効な列挙値である必要があります。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ko.xlf index 82a3bedc8cfb10..5045fc7f0857dd 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ko.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ko.xlf @@ -317,6 +317,16 @@ 진입점 마샬러 유형 '{0}'의 관리 유형은 'null'이 아니어야 합니다. + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. 'CustomMarshallerAttribute'의 'marshalMode' 인수는 'MarshalMode'의 유효한 열거형 값이어야 합니다. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pl.xlf index e8609dccaaf776..038ba046599538 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pl.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pl.xlf @@ -317,6 +317,16 @@ Typ zarządzany dla typu marshaller punktu wejścia „{0}” nie może mieć wartości „null” + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. Argument „marshalMode” atrybutu „CustomMarshaellerAttribute” musi być prawidłową wartością wyliczenia argumentu „MarshalMode”. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pt-BR.xlf index aa922df79def98..a4a9e3438c53df 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pt-BR.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.pt-BR.xlf @@ -317,6 +317,16 @@ O tipo gerenciado para o tipo de empacotador de ponto de entrada '{0}' não deve ser 'nulo' + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. O argumento 'marshalMode' de 'CustomMarshallerAttribute' deve ser um valor de enumeração válido de 'MarshalMode'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ru.xlf index eba3d3445b0c40..5e501346bc6735 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ru.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.ru.xlf @@ -317,6 +317,16 @@ Управляемый тип для типа маршалера точки входа "{0}" должен отличаться от "NULL" + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. Аргумент "marshalMode" атрибута "CustomMarshallerAttribute" должен быть допустимым перечисляемым значением "MarshalMode". diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.tr.xlf index 39173fb5d0cdd1..f1bf74978a1ccf 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.tr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.tr.xlf @@ -317,6 +317,16 @@ Giriş noktası hazırlayıcı türü '{0}' için yönetilen tür 'null' olmamalıdır + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hans.xlf index 6ed83988fdb531..a60088d63c9c94 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hans.xlf @@ -317,6 +317,16 @@ 入口点封送处理程序类型“{0}”的托管类型不能为“null” + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hant.xlf index f42923da7b2214..d75138671e16f5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.zh-Hant.xlf @@ -317,6 +317,16 @@ 進入點封送處理器類型 '{0}' 的受控類型不得為 'null' + + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for parameter '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + + + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + The specified 'MarshalAsAttribute' configuration for the return value of method '{1}' is not supported by source-generated P/Invokes. If the specified configuration is required, use a regular 'DllImport' instead. + + The 'marshalMode' argument of 'CustomMarshallerAttribute' must be a valid enum value of 'MarshalMode'. 'CustomMarshallerAttribute' 的 'marshalMode' 引數必須是有效的列舉值 'MarshalMode'。 diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/BoundGenerators.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/BoundGenerators.cs index af8364d9964104..d1516be7dab307 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/BoundGenerators.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/BoundGenerators.cs @@ -20,7 +20,7 @@ public sealed class BoundGenerators { private BoundGenerators() { } - public static BoundGenerators Create(ImmutableArray elementTypeInfo, IMarshallingGeneratorFactory generatorFactory, StubCodeContext context, IMarshallingGenerator fallbackGenerator, out ImmutableArray<(TypePositionInfo Info, MarshallingNotSupportedException Exception)> generatorBindingFailures) + public static BoundGenerators Create(ImmutableArray elementTypeInfo, IMarshallingGeneratorFactory generatorFactory, StubCodeContext context, IMarshallingGenerator fallbackGenerator, out ImmutableArray generatorBindingDiagnostics) { BoundGenerator defaultBoundGenerator = new BoundGenerator(new TypePositionInfo(SpecialTypeInfo.Void, NoMarshallingInfo.Instance), fallbackGenerator); BoundGenerators result = new(); @@ -28,7 +28,7 @@ public static BoundGenerators Create(ImmutableArray elementTyp ImmutableArray.Builder signatureMarshallers = ImmutableArray.CreateBuilder(); ImmutableArray.Builder nativeParamMarshallers = ImmutableArray.CreateBuilder(); ImmutableArray.Builder managedParamMarshallers = ImmutableArray.CreateBuilder(); - ImmutableArray<(TypePositionInfo Info, MarshallingNotSupportedException Exception)>.Builder bindingFailures = ImmutableArray.CreateBuilder<(TypePositionInfo, MarshallingNotSupportedException)>(); + ImmutableArray.Builder generatorDiagnostics = ImmutableArray.CreateBuilder(); BoundGenerator managedReturnMarshaller = defaultBoundGenerator; BoundGenerator nativeReturnMarshaller = defaultBoundGenerator; BoundGenerator managedExceptionMarshaller = defaultBoundGenerator; @@ -91,7 +91,7 @@ public static BoundGenerators Create(ImmutableArray elementTyp managedExceptionMarshaller = new(managedExceptionInfo, CreateGenerator(managedExceptionInfo, generatorFactory)); } - generatorBindingFailures = bindingFailures.ToImmutable(); + generatorBindingDiagnostics = generatorDiagnostics.ToImmutable(); return new BoundGenerators() { @@ -155,15 +155,9 @@ public static BoundGenerators Create(ImmutableArray elementTyp IMarshallingGenerator CreateGenerator(TypePositionInfo p, IMarshallingGeneratorFactory factory) { - try - { - return factory.Create(p, context); - } - catch (MarshallingNotSupportedException e) - { - bindingFailures.Add((p, e)); - return fallbackGenerator; - } + ResolvedGenerator generator = factory.Create(p, context); + generatorDiagnostics.AddRange(generator.Diagnostics); + return generator.ResolvedSuccessfully ? generator.Generator : fallbackGenerator; } } @@ -209,17 +203,21 @@ public ExtendedInvariantsValidator(ManagedTypeInfo nativeReturnType, IMarshallin _inner = inner; } - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) { - IMarshallingGenerator generator = _inner.Create(info, context); + ResolvedGenerator generator = _inner.Create(info, context); + if (!generator.ResolvedSuccessfully) + { + return generator; + } // Marshallers that share the native return position must have the same native return type. if (info.IsNativeReturnPosition - && generator.AsNativeType(info) != _nativeReturnType) + && generator.Generator.AsNativeType(info) != _nativeReturnType) { - throw new MarshallingNotSupportedException(info, context) + return ResolvedGenerator.NotSupported(new(info, context) { NotSupportedDetails = SR.MarshallerInNativeReturnPositionMustMatchNativeReturnType - }; + }); } return generator; } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/CustomMarshallingInfoHelper.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/CustomMarshallingInfoHelper.cs index e561f2f274a8d8..d3e456d37aacb4 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/CustomMarshallingInfoHelper.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/CustomMarshallingInfoHelper.cs @@ -17,7 +17,7 @@ internal static MarshallingInfo CreateNativeMarshallingInfo( GetMarshallingInfoCallback getMarshallingInfoCallback, int indirectionDepth, CountInfo parsedCountInfo, - IGeneratorDiagnostics diagnostics, + MarshallingInfoParserDiagnosticsBag diagnostics, Compilation compilation) { if (!ManualTypeMarshallingHelper.HasEntryPointMarshallerAttribute(entryPointType)) @@ -134,7 +134,7 @@ public static MarshallingInfo CreateNativeMarshallingInfoForNonSignatureElement( INamedTypeSymbol entryPointType, AttributeData attrData, Compilation compilation, - IGeneratorDiagnostics diagnostics) + MarshallingInfoParserDiagnosticsBag diagnostics) { if (!ManualTypeMarshallingHelper.HasEntryPointMarshallerAttribute(entryPointType)) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/DiagnosticInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/DiagnosticInfo.cs index 995de2c87fe2ef..ac4b62e8c4289e 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/DiagnosticInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/DiagnosticInfo.cs @@ -8,12 +8,12 @@ namespace Microsoft.Interop { - public record DiagnosticInfo + public sealed record DiagnosticInfo { public required DiagnosticDescriptor Descriptor { get; init; } public required SequenceEqualImmutableArray MessageArgs { get; init; } public required Location? Location { get; init; } - public required IEnumerable? AdditionalLocations { get; init; } + public required SequenceEqualImmutableArray? AdditionalLocations { get; init; } public required ValueEqualityImmutableDictionary? Properties { get; init; } public Diagnostic ToDiagnostic() => Diagnostic.Create( @@ -53,7 +53,7 @@ public static DiagnosticInfo Create(DiagnosticDescriptor descriptor, Location lo { Descriptor = descriptor, Location = location, - AdditionalLocations = additionalLocations, + AdditionalLocations = (additionalLocations ?? ImmutableArray.Empty).ToSequenceEqualImmutableArray(), Properties = properties.ToValueEquals(), MessageArgs = messageArgs.Select(o => o.ToString()).ToSequenceEqualImmutableArray() }; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalAsAttributeParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalAsAttributeParser.cs index aa9b25375c5beb..d0433fcb9fb5b5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalAsAttributeParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalAsAttributeParser.cs @@ -27,10 +27,10 @@ public sealed record MarshalAsInfo( public sealed class MarshalAsAttributeParser : IMarshallingInfoAttributeParser, IUseSiteAttributeParser { private readonly Compilation _compilation; - private readonly IGeneratorDiagnostics _diagnostics; + private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; private readonly DefaultMarshallingInfo _defaultInfo; - public MarshalAsAttributeParser(Compilation compilation, IGeneratorDiagnostics diagnostics, DefaultMarshallingInfo defaultInfo) + public MarshalAsAttributeParser(Compilation compilation, MarshallingInfoParserDiagnosticsBag diagnostics, DefaultMarshallingInfo defaultInfo) { _compilation = compilation; _diagnostics = diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalUsingAttributeParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalUsingAttributeParser.cs index e1bc06268be729..e65f92bbe136f8 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalUsingAttributeParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalUsingAttributeParser.cs @@ -15,9 +15,9 @@ namespace Microsoft.Interop public sealed class MarshalUsingAttributeParser : IMarshallingInfoAttributeParser, IUseSiteAttributeParser { private readonly Compilation _compilation; - private readonly IGeneratorDiagnostics _diagnostics; + private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; - public MarshalUsingAttributeParser(Compilation compilation, IGeneratorDiagnostics diagnostics) + public MarshalUsingAttributeParser(Compilation compilation, MarshallingInfoParserDiagnosticsBag diagnostics) { _compilation = compilation; _diagnostics = diagnostics; 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 990afd2ad37cf0..f55008fef06e7e 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 @@ -48,7 +48,7 @@ public AttributedMarshallingModelGeneratorFactory( private AttributedMarshallingModelOptions Options { get; } - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) { if (info.MarshallingAttributeInfo is NativeMarshallingAttributeInfo marshalInfo) { @@ -59,52 +59,79 @@ public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext conte { if (Options.RuntimeMarshallingDisabled || blittableInfo.IsStrictlyBlittable) { - return s_blittable; + return ResolvedGenerator.Resolved(s_blittable); } - throw new MarshallingNotSupportedException(info, context) + return ResolvedGenerator.NotSupported( + new GeneratorDiagnostic.NotSupported(info, context) { NotSupportedDetails = SR.RuntimeMarshallingMustBeDisabled, DiagnosticProperties = AddDisableRuntimeMarshallingAttributeProperties - }; + }); } if (info.MarshallingAttributeInfo is MissingSupportMarshallingInfo) { - return s_forwarder; + return ResolvedGenerator.Resolved(s_forwarder); } return _innerMarshallingGenerator.Create(info, context); } - private ExpressionSyntax GetNumElementsExpressionFromMarshallingInfo(TypePositionInfo info, CountInfo count, StubCodeContext context) + private record struct ExpressionOrNotSupported(ExpressionSyntax? Expression, GeneratorDiagnostic.NotSupported? NotSupported) + { + public ExpressionOrNotSupported(ExpressionSyntax expression) + : this(expression, null) + { + } + public ExpressionOrNotSupported(GeneratorDiagnostic.NotSupported notSupportedDiagnostic) + : this(null, notSupportedDiagnostic) + { + } + } + + private ExpressionOrNotSupported GetNumElementsExpressionFromMarshallingInfo(TypePositionInfo info, CountInfo count, StubCodeContext context) { switch (count) { case SizeAndParamIndexInfo(int size, SizeAndParamIndexInfo.UnspecifiedParam): - return GetConstSizeExpression(size); + return new(GetConstSizeExpression(size)); case ConstSizeCountInfo(int size): - return GetConstSizeExpression(size); + return new(GetConstSizeExpression(size)); case SizeAndParamIndexInfo(SizeAndParamIndexInfo.UnspecifiedConstSize, TypePositionInfo param): { - ExpressionSyntax expr = GetExpressionForParam(param, out bool isIntType); - return isIntType ? expr : CheckedExpression(SyntaxKind.CheckedExpression, expr); + return GetExpressionForParam(param, out bool isIntType) switch + { + (ExpressionSyntax expr, null) => new(isIntType ? expr : CheckedExpression(SyntaxKind.CheckedExpression, expr)), + (null, GeneratorDiagnostic.NotSupported notSupported) => new(notSupported), + (not null, not null) => throw new UnreachableException() + }; } case SizeAndParamIndexInfo(int size, TypePositionInfo param): - return CheckedExpression(SyntaxKind.CheckedExpression, + return GetExpressionForParam(param, out bool _) switch + { + (ExpressionSyntax expr, null) => new( + CheckedExpression(SyntaxKind.CheckedExpression, BinaryExpression(SyntaxKind.AddExpression, GetConstSizeExpression(size), - GetExpressionForParam(param, out _))); + expr))), + (null, GeneratorDiagnostic.NotSupported notSupported) => new(notSupported), + (not null, not null) => throw new UnreachableException() + }; case CountElementCountInfo(TypePositionInfo elementInfo): { - ExpressionSyntax expr = GetExpressionForParam(elementInfo, out bool isIntType); - return isIntType ? expr : CheckedExpression(SyntaxKind.CheckedExpression, expr); + return GetExpressionForParam(elementInfo, out bool isIntType) switch + { + (ExpressionSyntax expr, null) => new(isIntType ? expr : CheckedExpression(SyntaxKind.CheckedExpression, expr)), + (null, GeneratorDiagnostic.NotSupported notSupported) => new(notSupported), + (not null, not null) => throw new UnreachableException() + }; } default: - throw new MarshallingNotSupportedException(info, context) + return new(new GeneratorDiagnostic.NotSupported(info, context) { NotSupportedDetails = SR.ArraySizeMustBeSpecified - }; + }); } static LiteralExpressionSyntax GetConstSizeExpression(int size) @@ -112,7 +139,7 @@ static LiteralExpressionSyntax GetConstSizeExpression(int size) return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(size)); } - ExpressionSyntax GetExpressionForParam(TypePositionInfo paramInfo, out bool isIntType) + ExpressionOrNotSupported GetExpressionForParam(TypePositionInfo paramInfo, out bool isIntType) { ExpressionSyntax numElementsExpression = GetIndexedNumElementsExpression( context, @@ -132,27 +159,29 @@ ExpressionSyntax GetExpressionForParam(TypePositionInfo paramInfo, out bool isIn } else { - throw new MarshallingNotSupportedException(info, context) + isIntType = false; + return new(new GeneratorDiagnostic.NotSupported(info, context) { NotSupportedDetails = SR.CollectionSizeParamTypeMustBeIntegral - }; + }); } } if (type is not SpecialTypeInfo specialType || !specialType.SpecialType.IsIntegralType()) { - throw new MarshallingNotSupportedException(info, context) + isIntType = false; + return new(new GeneratorDiagnostic.NotSupported(info, context) { NotSupportedDetails = SR.CollectionSizeParamTypeMustBeIntegral - }; + }); } isIntType = specialType.SpecialType == SpecialType.System_Int32; - return isIntType + return new(isIntType ? numElementsExpression : CastExpression( PredefinedType(Token(SyntaxKind.IntKeyword)), - ParenthesizedExpression(numElementsExpression)); + ParenthesizedExpression(numElementsExpression))); } static ExpressionSyntax GetIndexedNumElementsExpression(StubCodeContext context, TypePositionInfo numElementsInfo, out int numIndirectionLevels) @@ -213,18 +242,21 @@ private CustomTypeMarshallerData GetMarshallerDataForTypePositionInfo(CustomType }; } - private IMarshallingGenerator CreateCustomNativeTypeMarshaller(TypePositionInfo info, StubCodeContext context, NativeMarshallingAttributeInfo marshalInfo) + private ResolvedGenerator CreateCustomNativeTypeMarshaller(TypePositionInfo info, StubCodeContext context, NativeMarshallingAttributeInfo marshalInfo) { - ValidateCustomNativeTypeMarshallingSupported(info, context, marshalInfo); + if (ValidateCustomNativeTypeMarshallingSupported(info, context, marshalInfo) is GeneratorDiagnostic.NotSupported diagnostic) + { + return ResolvedGenerator.NotSupported(diagnostic); + } CustomTypeMarshallerData marshallerData = GetMarshallerDataForTypePositionInfo(marshalInfo.Marshallers, info, context); if (!ValidateRuntimeMarshallingOptions(marshallerData)) { - throw new MarshallingNotSupportedException(info, context) + return ResolvedGenerator.NotSupported(new(info, context) { NotSupportedDetails = SR.RuntimeMarshallingMustBeDisabled, DiagnosticProperties = AddDisableRuntimeMarshallingAttributeProperties - }; + }); } // Collections have extra configuration, so handle them separately. @@ -269,10 +301,10 @@ private IMarshallingGenerator CreateCustomNativeTypeMarshaller(TypePositionInfo marshallingGenerator = new StaticPinnableManagedValueMarshaller(marshallingGenerator, marshallerData.MarshallerType.Syntax); } - return marshallingGenerator; + return ResolvedGenerator.Resolved(marshallingGenerator); } - private IMarshallingGenerator CreateNativeCollectionMarshaller( + private ResolvedGenerator CreateNativeCollectionMarshaller( TypePositionInfo info, StubCodeContext context, CustomTypeMarshallerData marshallerData, @@ -280,18 +312,30 @@ private IMarshallingGenerator CreateNativeCollectionMarshaller( { var elementInfo = new TypePositionInfo(marshallerData.CollectionElementType, marshallerData.CollectionElementMarshallingInfo) { + InstanceIdentifier = info.InstanceIdentifier, ManagedIndex = info.ManagedIndex, RefKind = CreateElementRefKind(info.RefKind, info.ByValueContentsMarshalKind) }; - IMarshallingGenerator elementMarshaller = _elementMarshallingGenerator.Create( + ResolvedGenerator resolvedElementMarshaller = _elementMarshallingGenerator.Create( elementInfo, new LinearCollectionElementMarshallingCodeContext(StubCodeContext.Stage.Setup, string.Empty, string.Empty, context)); + if (!resolvedElementMarshaller.ResolvedSuccessfully) + { + return resolvedElementMarshaller; + } + IMarshallingGenerator elementMarshaller = resolvedElementMarshaller.Generator; + ExpressionSyntax numElementsExpression = LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)); if (MarshallerHelpers.GetMarshalDirection(info, context) != MarshalDirection.ManagedToUnmanaged) { // In this case, we need a numElementsExpression supplied from metadata, so we'll calculate it here. - numElementsExpression = GetNumElementsExpressionFromMarshallingInfo(info, marshalInfo.ElementCountInfo, context); + ExpressionOrNotSupported numElementsExpressionResult = GetNumElementsExpressionFromMarshallingInfo(info, marshalInfo.ElementCountInfo, context); + if (numElementsExpressionResult is (_, GeneratorDiagnostic.NotSupported notSupportedDiagnostic)) + { + return ResolvedGenerator.NotSupported(notSupportedDiagnostic); + } + numElementsExpression = numElementsExpressionResult.Expression; } // Insert the unmanaged element type into the marshaller type @@ -392,7 +436,7 @@ private IMarshallingGenerator CreateNativeCollectionMarshaller( marshallingGenerator = new StaticPinnableManagedValueMarshaller(marshallingGenerator, marshallerTypeSyntax); } - return marshallingGenerator; + return ResolvedGenerator.Resolved(marshallingGenerator); } private enum FreeStrategy @@ -472,14 +516,14 @@ private static TypeSyntax ReplacePlaceholderSyntaxWithUnmanagedTypeSyntax( originalTypeSyntax.DescendantNodesAndSelf().OfType().Where(t => t.IsEquivalentTo(marshalInfo.PlaceholderTypeParameter.Syntax)), (_, _) => unmanagedElementType); - private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info, StubCodeContext context, NativeMarshallingAttributeInfo marshalInfo) + private GeneratorDiagnostic.NotSupported? ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info, StubCodeContext context, NativeMarshallingAttributeInfo marshalInfo) { MarshalDirection elementDirection = MarshallerHelpers.GetMarshalDirection(info, context); // Marshalling out or return parameter, but no out marshaller is specified if (elementDirection == MarshalDirection.UnmanagedToManaged && !marshalInfo.Marshallers.IsDefinedOrDefault(Options.UnmanagedToManagedMode)) { - throw new MarshallingNotSupportedException(info, context) + return new(info, context) { NotSupportedDetails = SR.Format(SR.UnmanagedToManagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName) }; @@ -489,7 +533,7 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info, if (elementDirection == MarshalDirection.Bidirectional && !marshalInfo.Marshallers.IsDefinedOrDefault(Options.BidirectionalMode)) { - throw new MarshallingNotSupportedException(info, context) + return new(info, context) { NotSupportedDetails = SR.Format(SR.BidirectionalMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName) }; @@ -499,11 +543,13 @@ private void ValidateCustomNativeTypeMarshallingSupported(TypePositionInfo info, if (elementDirection == MarshalDirection.ManagedToUnmanaged && !marshalInfo.Marshallers.IsDefinedOrDefault(Options.ManagedToUnmanagedMode)) { - throw new MarshallingNotSupportedException(info, context) + return new(info, context) { NotSupportedDetails = SR.Format(SR.ManagedToUnmanagedMissingRequiredMarshaller, marshalInfo.EntryPointType.FullTypeName) }; } + + return null; } private static RefKind CreateElementRefKind(RefKind refKind, ByValueContentsMarshalKind byValueContentsMarshalKind) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs index c5112e2ed49c3b..991a0ebd35953a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs @@ -19,14 +19,15 @@ public ByValueContentsMarshalKindValidator(IMarshallingGeneratorFactory inner) _inner = inner; } - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) { - return ValidateByValueMarshalKind(info, context, _inner.Create(info, context)); + ResolvedGenerator generator = _inner.Create(info, context); + return generator.ResolvedSuccessfully ? ValidateByValueMarshalKind(info, context, generator) : generator; } - private static IMarshallingGenerator ValidateByValueMarshalKind(TypePositionInfo info, StubCodeContext context, IMarshallingGenerator generator) + private static ResolvedGenerator ValidateByValueMarshalKind(TypePositionInfo info, StubCodeContext context, ResolvedGenerator generator) { - if (generator is Forwarder) + if (generator.Generator is Forwarder) { // Forwarder allows everything since it just forwards to a P/Invoke. return generator; @@ -34,24 +35,33 @@ private static IMarshallingGenerator ValidateByValueMarshalKind(TypePositionInfo if (info.IsByRef && info.ByValueContentsMarshalKind != ByValueContentsMarshalKind.Default) { - throw new MarshallingNotSupportedException(info, context) + return generator with { + Diagnostics = generator.Diagnostics.Add(new GeneratorDiagnostic.NotSupported(info, context) + { NotSupportedDetails = SR.InOutAttributeByRefNotSupported + }) }; } else if (info.ByValueContentsMarshalKind == ByValueContentsMarshalKind.In) { - throw new MarshallingNotSupportedException(info, context) + return generator with { + Diagnostics = generator.Diagnostics.Add(new GeneratorDiagnostic.NotSupported(info, context) + { NotSupportedDetails = SR.InAttributeNotSupportedWithoutOut - }; - } - else if (info.ByValueContentsMarshalKind != ByValueContentsMarshalKind.Default + }) + }; + } + else if (info.ByValueContentsMarshalKind != ByValueContentsMarshalKind.Default) && !generator.SupportsByValueMarshalKind(info.ByValueContentsMarshalKind, context)) + // TODO: Emit diagnostic for unnecesary attributes instead of failing the compilation. + return generator with { - throw new MarshallingNotSupportedException(info, context) + Diagnostics = generator.Diagnostics.Add(new GeneratorDiagnostic.NotSupported(info, context) { NotSupportedDetails = SR.InOutAttributeMarshalerNotSupported + }) }; } return generator; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshallingGeneratorFactory.cs index f9ef0ad8de50a5..bb43170cce7900 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshallingGeneratorFactory.cs @@ -33,7 +33,7 @@ public CharMarshallingGeneratorFactory(IMarshallingGeneratorFactory inner, bool _stringMarshallingAttribute = stringMarshallingAttribute; } - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) { if (info.ManagedType is SpecialTypeInfo { SpecialType: SpecialType.System_Char }) { @@ -43,16 +43,16 @@ public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext conte return _inner.Create(info, context); } - private IMarshallingGenerator CreateCharMarshaller(TypePositionInfo info, StubCodeContext context) + private ResolvedGenerator CreateCharMarshaller(TypePositionInfo info, StubCodeContext context) { MarshallingInfo marshalInfo = info.MarshallingAttributeInfo; if (marshalInfo is NoMarshallingInfo) { // [Compat] Require explicit marshalling information. - throw new MarshallingNotSupportedException(info, context) + return ResolvedGenerator.NotSupported(new(info, context) { NotSupportedDetails = string.Format(SR.MarshallingStringOrCharAsUndefinedNotSupported, _stringMarshallingAttribute) - }; + }); } // Explicit MarshalAs takes precedence over string encoding info @@ -62,7 +62,7 @@ private IMarshallingGenerator CreateCharMarshaller(TypePositionInfo info, StubCo { case UnmanagedType.I2: case UnmanagedType.U2: - return _useBlittableMarshallerForUtf16 ? s_blittable : s_utf16Char; + return ResolvedGenerator.Resolved(_useBlittableMarshallerForUtf16 ? s_blittable : s_utf16Char); } } else if (marshalInfo is MarshallingInfoStringSupport marshalStringInfo) @@ -70,21 +70,21 @@ private IMarshallingGenerator CreateCharMarshaller(TypePositionInfo info, StubCo switch (marshalStringInfo.CharEncoding) { case CharEncoding.Utf16: - return _useBlittableMarshallerForUtf16 ? s_blittable : s_utf16Char; + return ResolvedGenerator.Resolved(_useBlittableMarshallerForUtf16 ? s_blittable : s_utf16Char); case CharEncoding.Utf8: - throw new MarshallingNotSupportedException(info, context) // [Compat] UTF-8 is not supported for char + return ResolvedGenerator.NotSupported(new(info, context) // [Compat] UTF-8 is not supported for char { NotSupportedDetails = SR.Format(SR.MarshallingCharAsSpecifiedStringMarshallingNotSupported, nameof(CharEncoding.Utf8)) - }; + }); case CharEncoding.Custom: - throw new MarshallingNotSupportedException(info, context) + return ResolvedGenerator.NotSupported(new(info, context) { NotSupportedDetails = SR.MarshallingCharAsStringMarshallingCustomNotSupported - }; + }); } } - throw new MarshallingNotSupportedException(info, context); + return ResolvedGenerator.NotSupported(new(info, context)); } } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/GeneratorDiagnostic.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/GeneratorDiagnostic.cs new file mode 100644 index 00000000000000..c82819d0ae46fd --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/GeneratorDiagnostic.cs @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Immutable; +using System.Linq; +using Microsoft.CodeAnalysis; + +namespace Microsoft.Interop +{ + public abstract record GeneratorDiagnostic + { + private GeneratorDiagnostic(TypePositionInfo typePositionInfo, StubCodeContext stubCodeContext, bool isFatal) + { + TypePositionInfo = typePositionInfo; + StubCodeContext = stubCodeContext; + IsFatal = isFatal; + } + + /// + /// [Optional] Properties to attach to any diagnostic emitted due to this exception. + /// + public ImmutableDictionary? DiagnosticProperties { get; init; } + public TypePositionInfo TypePositionInfo { get; } + public StubCodeContext StubCodeContext { get; } + public bool IsFatal { get; } + + public abstract DiagnosticInfo ToDiagnosticInfo(DiagnosticDescriptor descriptor, Location location, string elementName); + + public sealed record NotSupported(TypePositionInfo TypePositionInfo, StubCodeContext StubCodeContext) : GeneratorDiagnostic(TypePositionInfo, StubCodeContext, isFatal: true) + { + /// + /// [Optional] Specific reason marshalling of the supplied type isn't supported. + /// + public string? NotSupportedDetails { get; init; } + + public override DiagnosticInfo ToDiagnosticInfo(DiagnosticDescriptor descriptor, Location location, string elementName) + { + if (NotSupportedDetails is not null) + { + return DiagnosticInfo.Create(descriptor, location, DiagnosticProperties, NotSupportedDetails, elementName); + } + return DiagnosticInfo.Create(descriptor, location, DiagnosticProperties, TypePositionInfo.ManagedType.DiagnosticFormattedName, elementName); + } + } + + public sealed record UnnecessaryData(TypePositionInfo TypePositionInfo, StubCodeContext StubCodeContext, ImmutableArray UnnecessaryDataLocations) : GeneratorDiagnostic(TypePositionInfo, StubCodeContext, isFatal: false) + { + public required string UnnecessaryDataDetails { get; init; } + + public override DiagnosticInfo ToDiagnosticInfo(DiagnosticDescriptor descriptor, Location location, string elementName) + { + return DiagnosticInfo.Create( + descriptor, + location, + UnnecessaryDataLocations, + // Add "unnecessary locations" property so the IDE fades the right locations. + DiagnosticProperties.Add(WellKnownDiagnosticTags.Unnecessary, $"[{string.Join(",", Enumerable.Range(0, UnnecessaryDataLocations.Length))}]"), + UnnecessaryDataDetails, + elementName); + } + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/IMarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/IMarshallingGeneratorFactory.cs index 1065cae4dfce32..df72e1e2f2822a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/IMarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/IMarshallingGeneratorFactory.cs @@ -10,12 +10,12 @@ namespace Microsoft.Interop public interface IMarshallingGeneratorFactory { /// - /// Create an instance for marshalling the supplied type in the given position. + /// Create an instance for marshalling the supplied type in the given position and collect any diagnostics from generator resolution. /// /// Type details /// Metadata about the stub the type is associated with - /// A instance. - public IMarshallingGenerator Create( + /// A instance. + public ResolvedGenerator Create( TypePositionInfo info, StubCodeContext context); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshalAsMarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshalAsMarshallingGeneratorFactory.cs index 1790e588a8e790..ceb13bf94c57dc 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshalAsMarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshalAsMarshallingGeneratorFactory.cs @@ -34,7 +34,7 @@ public MarshalAsMarshallingGeneratorFactory(InteropGenerationOptions options, IM /// Type details /// Metadata about the stub the type is associated with /// A instance. - public IMarshallingGenerator Create( + public ResolvedGenerator Create( TypePositionInfo info, StubCodeContext context) { @@ -53,7 +53,7 @@ public IMarshallingGenerator Create( or { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_UIntPtr }, MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.SysUInt, _) } or { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Single }, MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.R4, _) } or { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Double }, MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.R8, _) }: - return s_blittable; + return ResolvedGenerator.Resolved(s_blittable); // Enum with no marshalling info case { ManagedType: EnumTypeInfo enumType, MarshallingAttributeInfo: NoMarshallingInfo }: @@ -61,48 +61,48 @@ public IMarshallingGenerator Create( SpecialType underlyingSpecialType = enumType.UnderlyingType; if (underlyingSpecialType == SpecialType.System_Boolean || underlyingSpecialType == SpecialType.System_Char) { - throw new MarshallingNotSupportedException(info, context); + return ResolvedGenerator.NotSupported(new(info, context)); } - return s_blittable; + return ResolvedGenerator.Resolved(s_blittable); // Pointer with no marshalling info case { ManagedType: PointerTypeInfo(_, _, IsFunctionPointer: false), MarshallingAttributeInfo: NoMarshallingInfo }: - return s_blittable; + return ResolvedGenerator.Resolved(s_blittable); // Function pointer with no marshalling info case { ManagedType: PointerTypeInfo(_, _, IsFunctionPointer: true), MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.FunctionPtr, _) }: - return s_blittable; + return ResolvedGenerator.Resolved(s_blittable); case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Boolean }, MarshallingAttributeInfo: MarshalAsInfo(UnmanagedType.U1, _) }: - return s_byteBool; + return ResolvedGenerator.Resolved(s_byteBool); case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Boolean }, MarshallingAttributeInfo: MarshalAsInfo(UnmanagedType.I1, _) }: - return s_signed_byteBool; + return ResolvedGenerator.Resolved(s_signed_byteBool); case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Boolean }, MarshallingAttributeInfo: MarshalAsInfo(UnmanagedType.U4, _) }: - return s_winBool; + return ResolvedGenerator.Resolved(s_winBool); case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Boolean }, MarshallingAttributeInfo: MarshalAsInfo(UnmanagedType.I4 or UnmanagedType.Bool, _) }: - return s_signed_winBool; + return ResolvedGenerator.Resolved(s_signed_winBool); case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Boolean }, MarshallingAttributeInfo: MarshalAsInfo(UnmanagedType.VariantBool, _) }: - return s_variantBool; + return ResolvedGenerator.Resolved(s_variantBool); case { ManagedType: DelegateTypeInfo, MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.FunctionPtr, _) }: - return s_delegate; + return ResolvedGenerator.Resolved(s_delegate); case { MarshallingAttributeInfo: SafeHandleMarshallingInfo(_, bool isAbstract) }: if (!context.AdditionalTemporaryStateLivesAcrossStages || context.Direction != MarshalDirection.ManagedToUnmanaged) { - throw new MarshallingNotSupportedException(info, context); + return ResolvedGenerator.NotSupported(new(info, context)); } if (info.IsByRef && isAbstract) { - throw new MarshallingNotSupportedException(info, context) + return ResolvedGenerator.NotSupported(new(info, context) { NotSupportedDetails = SR.SafeHandleByRefMustBeConcrete - }; + }); } - return s_safeHandle; + return ResolvedGenerator.Resolved(s_safeHandle); case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Void } }: - return s_forwarder; + return ResolvedGenerator.Resolved(s_forwarder); default: return InnerFactory.Create(info, 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 4e6a749af66a52..7a5a4ecc3d72cd 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 @@ -138,42 +138,4 @@ public interface IMarshallingGenerator /// bool SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context); } - - - /// - /// Exception used to indicate marshalling isn't supported. - /// - public sealed class MarshallingNotSupportedException : Exception - { - /// - /// Construct a new instance. - /// - /// instance - /// instance - public MarshallingNotSupportedException(TypePositionInfo info, StubCodeContext context) - { - TypePositionInfo = info; - StubCodeContext = context; - } - - /// - /// Type that is being marshalled. - /// - public TypePositionInfo TypePositionInfo { get; private init; } - - /// - /// Context in which the marshalling is taking place. - /// - public StubCodeContext StubCodeContext { get; private init; } - - /// - /// [Optional] Specific reason marshalling of the supplied type isn't supported. - /// - public string? NotSupportedDetails { get; init; } - - /// - /// [Optional] Properties to attach to any diagnostic emitted due to this exception. - /// - public ImmutableDictionary? DiagnosticProperties { get; init; } - } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/NoMarshallingInfoErrorMarshallingFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/NoMarshallingInfoErrorMarshallingFactory.cs index c7a7123dfaabb3..5d71d56896f847 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/NoMarshallingInfoErrorMarshallingFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/NoMarshallingInfoErrorMarshallingFactory.cs @@ -13,16 +13,16 @@ public sealed class NoMarshallingInfoErrorMarshallingFactory : IMarshallingGener { private readonly IMarshallingGeneratorFactory _inner; - public IMarshallingGenerator Create( + public ResolvedGenerator Create( TypePositionInfo info, StubCodeContext context) { if (info.MarshallingAttributeInfo is NoMarshallingInfo && CustomTypeToErrorMessageMap.TryGetValue(info.ManagedType, out string errorMessage)) { - throw new MarshallingNotSupportedException(info, context) + return ResolvedGenerator.NotSupported(new(info, context) { NotSupportedDetails = errorMessage - }; + }); } return _inner.Create(info, context); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ResolvedGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ResolvedGenerator.cs new file mode 100644 index 00000000000000..b2fdeb39e63da5 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ResolvedGenerator.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Immutable; +using System.Linq; + +namespace Microsoft.Interop +{ + public record struct ResolvedGenerator(IMarshallingGenerator Generator, ImmutableArray Diagnostics) + { + private static readonly Forwarder s_forwarder = new(); + + private bool? _resolvedSuccessfully; + + public bool ResolvedSuccessfully => _resolvedSuccessfully ??= Diagnostics.All(d => !d.IsFatal); + + public static ResolvedGenerator Resolved(IMarshallingGenerator generator) + { + return new(generator, ImmutableArray.Empty); + } + + public static ResolvedGenerator NotSupported(GeneratorDiagnostic.NotSupported notSupportedDiagnostic) + { + return new(s_forwarder, ImmutableArray.Create(notSupportedDiagnostic)); + } + + public static ResolvedGenerator ResolvedWithDiagnostics(IMarshallingGenerator generator, ImmutableArray diagnostics) + { + return new(generator, diagnostics); + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/UnsupportedMarshallingFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/UnsupportedMarshallingFactory.cs index 16047e9c3fa3be..109c36a2e8ad3c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/UnsupportedMarshallingFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/UnsupportedMarshallingFactory.cs @@ -1,17 +1,11 @@ // 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.Collections.Generic; -using System.Collections.Immutable; -using System.Runtime.InteropServices; -using Microsoft.CodeAnalysis; - namespace Microsoft.Interop { public sealed class UnsupportedMarshallingFactory : IMarshallingGeneratorFactory { - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) => - throw new MarshallingNotSupportedException(info, context); + public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context) => + ResolvedGenerator.NotSupported(new(info, context)); } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs index 7629c68e9713c4..4a896eda28ad16 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs @@ -174,7 +174,7 @@ public static bool TryGetInfoForParamIndex(this IElementInfoProvider provider, A /// public sealed class MarshallingInfoParser { - private readonly IGeneratorDiagnostics _diagnostics; + private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; private readonly IElementInfoProvider _elementInfoProvider; private readonly ImmutableArray _useSiteMarshallingAttributeParsers; private readonly ImmutableArray _marshallingAttributeParsers; @@ -189,7 +189,7 @@ public sealed class MarshallingInfoParser /// Parsers for retrieving marshalling information from attributes and the managed type. /// Parsers for retrieving marshalling information from the managed type only. public MarshallingInfoParser( - IGeneratorDiagnostics diagnostics, + MarshallingInfoParserDiagnosticsBag diagnostics, IElementInfoProvider elementInfoProvider, ImmutableArray useSiteMarshallingAttributeParsers, ImmutableArray marshallingAttributeParsers, @@ -286,9 +286,9 @@ internal sealed class CycleDetectingElementInfoProvider : IElementInfoProvider { private ImmutableHashSet _activeInspectingElements = ImmutableHashSet.Empty; private readonly IElementInfoProvider _innerProvider; - private readonly IGeneratorDiagnostics _diagnostics; + private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; - public CycleDetectingElementInfoProvider(IElementInfoProvider innerProvider, IGeneratorDiagnostics diagnostics) + public CycleDetectingElementInfoProvider(IElementInfoProvider innerProvider, MarshallingInfoParserDiagnosticsBag diagnostics) { _innerProvider = innerProvider; _diagnostics = diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IGeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParserDiagnosticsBag.cs similarity index 72% rename from src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IGeneratorDiagnostics.cs rename to src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParserDiagnosticsBag.cs index e620875eae719f..35f5dda81427d7 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IGeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParserDiagnosticsBag.cs @@ -1,8 +1,10 @@ // 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.Collections.Generic; using System.Collections.Immutable; +using System.Resources; using Microsoft.CodeAnalysis; namespace Microsoft.Interop @@ -219,28 +221,85 @@ public static DiagnosticInfo CreateDiagnosticInfo( } - public interface IGeneratorDiagnostics + public class MarshallingInfoParserDiagnosticsBag { + private readonly IDiagnosticDescriptorProvider _descriptorProvider; + private readonly GeneratorDiagnosticBag _diagnostics; + private readonly ResourceManager _resourceManager; + private readonly Type _resourceSource; + + public MarshallingInfoParserDiagnosticsBag(IDiagnosticDescriptorProvider descriptorProvider, GeneratorDiagnosticBag diagnostics, ResourceManager resourceManager, Type resourceSource) + { + _descriptorProvider = descriptorProvider; + _diagnostics = diagnostics; + _resourceManager = resourceManager; + _resourceSource = resourceSource; + } + /// /// Report diagnostic for configuration that is not supported by the DLL import source generator /// /// Attribute specifying the unsupported configuration /// Name of the configuration /// [Optiona] Unsupported configuration value - void ReportConfigurationNotSupported( + public void ReportConfigurationNotSupported( AttributeData attributeData, string configurationName, - string? unsupportedValue); + string? unsupportedValue) + { + _diagnostics.ReportConfigurationNotSupported(_descriptorProvider, attributeData, configurationName, unsupportedValue); + } - void ReportInvalidMarshallingAttributeInfo( + public void ReportInvalidMarshallingAttributeInfo( AttributeData attributeData, string reasonResourceName, - params string[] reasonArgs); + params string[] reasonArgs) + { + _diagnostics.ReportInvalidMarshallingAttributeInfo(_descriptorProvider, attributeData, _resourceManager, _resourceSource, reasonResourceName, reasonArgs); + } + } + + public class GeneratorDiagnosticBag + { + private readonly List _diagnostics = new List(); + public IEnumerable Diagnostics => _diagnostics; + + public void ReportDiagnostic(DiagnosticInfo diagnostic) + { + _diagnostics.Add(diagnostic); + } + + public void ReportConfigurationNotSupported(IDiagnosticDescriptorProvider descriptorProvider, AttributeData attributeData, string configurationName, string? unsupportedValue) + { + if (unsupportedValue is null) + { + ReportDiagnostic(attributeData.CreateDiagnosticInfo(descriptorProvider.GetConfigurationNotSupportedDescriptor(withValue: false), configurationName)); + } + else + { + ReportDiagnostic(attributeData.CreateDiagnosticInfo(descriptorProvider.GetConfigurationNotSupportedDescriptor(withValue: true), unsupportedValue, configurationName)); + } + } + + public void ReportInvalidMarshallingAttributeInfo(IDiagnosticDescriptorProvider descriptorProvider, AttributeData attributeData, ResourceManager resourceManager, Type resourceSource, string reasonResourceName, params string[] reasonArgs) + { + ReportDiagnostic(attributeData.CreateDiagnosticInfo(descriptorProvider.InvalidMarshallingAttributeInfo, new LocalizableResourceString(reasonResourceName, resourceManager, resourceSource, reasonArgs))); + } + + public void ReportGeneratorDiagnostic(IDiagnosticDescriptorProvider descriptorProvider, ISignatureDiagnosticLocations locations, GeneratorDiagnostic diagnostic) + { + _diagnostics.Add(locations.CreateDiagnosticInfo(descriptorProvider, diagnostic)); + } + + public void ReportConfigurationNotSupported(IDiagnosticDescriptorProvider descriptorProvider, AttributeData attributeData, string configurationName) + { + ReportDiagnostic(attributeData.CreateDiagnosticInfo(descriptorProvider.GetConfigurationNotSupportedDescriptor(withValue: false), configurationName)); + } } public static class IGeneratorDiagnosticsExtensions { - public static void ReportConfigurationNotSupported(this IGeneratorDiagnostics diagnostics, AttributeData attributeData, string configurationName) + public static void ReportConfigurationNotSupported(this MarshallingInfoParserDiagnosticsBag diagnostics, AttributeData attributeData, string configurationName) => diagnostics.ReportConfigurationNotSupported(attributeData, configurationName, null); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureDiagnosticLocations.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureDiagnosticLocations.cs index 80607c56687224..d530b04cfb043f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureDiagnosticLocations.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureDiagnosticLocations.cs @@ -9,7 +9,19 @@ namespace Microsoft.Interop { - public sealed record MethodSignatureDiagnosticLocations(string MethodIdentifier, ImmutableArray ManagedParameterLocations, Location FallbackLocation) + public interface IDiagnosticDescriptorProvider + { + DiagnosticDescriptor InvalidMarshallingAttributeInfo { get; } + DiagnosticDescriptor GetConfigurationNotSupportedDescriptor(bool withValue); + DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic); + } + + public interface ISignatureDiagnosticLocations + { + DiagnosticInfo CreateDiagnosticInfo(IDiagnosticDescriptorProvider descriptorProvider, GeneratorDiagnostic diagnostic); + } + + public sealed record MethodSignatureDiagnosticLocations(string MethodIdentifier, ImmutableArray ManagedParameterLocations, Location FallbackLocation) : ISignatureDiagnosticLocations { public MethodSignatureDiagnosticLocations(MethodDeclarationSyntax syntax) : this(syntax.Identifier.Text, syntax.ParameterList.Parameters.Select(p => p.Identifier.GetLocation()).ToImmutableArray(), syntax.Identifier.GetLocation()) @@ -24,5 +36,16 @@ public bool Equals(MethodSignatureDiagnosticLocations other) } public override int GetHashCode() => throw new UnreachableException(); + + public DiagnosticInfo CreateDiagnosticInfo(IDiagnosticDescriptorProvider descriptorProvider, GeneratorDiagnostic diagnostic) + { + DiagnosticDescriptor descriptor = descriptorProvider.GetDescriptor(diagnostic); + var (location, elementName) = diagnostic.TypePositionInfo switch + { + { ManagedIndex: >= 0 and int index, InstanceIdentifier: string identifier } => (ManagedParameterLocations[index], identifier), + _ => (FallbackLocation, MethodIdentifier), + }; + return diagnostic.ToDiagnosticInfo(descriptor, location, elementName); + } } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureElementInfoProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureElementInfoProvider.cs index e00eef6d2c0aea..cebdfe8404b9ad 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureElementInfoProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureElementInfoProvider.cs @@ -12,11 +12,11 @@ namespace Microsoft.Interop public sealed class MethodSignatureElementInfoProvider : IElementInfoProvider { private readonly Compilation _compilation; - private readonly IGeneratorDiagnostics _generatorDiagnostics; + private readonly MarshallingInfoParserDiagnosticsBag _generatorDiagnostics; private readonly IMethodSymbol _method; private readonly ImmutableArray _useSiteAttributeParsers; - public MethodSignatureElementInfoProvider(Compilation compilation, IGeneratorDiagnostics generatorDiagnostics, IMethodSymbol method, ImmutableArray useSiteAttributeParsers) + public MethodSignatureElementInfoProvider(Compilation compilation, MarshallingInfoParserDiagnosticsBag generatorDiagnostics, IMethodSymbol method, ImmutableArray useSiteAttributeParsers) { _compilation = compilation; _generatorDiagnostics = generatorDiagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/NativeMarshallingAttributeParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/NativeMarshallingAttributeParser.cs index c51116029143e7..0c17cf405fe715 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/NativeMarshallingAttributeParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/NativeMarshallingAttributeParser.cs @@ -9,9 +9,9 @@ namespace Microsoft.Interop public sealed class NativeMarshallingAttributeParser : IMarshallingInfoAttributeParser { private readonly Compilation _compilation; - private readonly IGeneratorDiagnostics _diagnostics; + private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; - public NativeMarshallingAttributeParser(Compilation compilation, IGeneratorDiagnostics diagnostics) + public NativeMarshallingAttributeParser(Compilation compilation, MarshallingInfoParserDiagnosticsBag diagnostics) { _compilation = compilation; _diagnostics = diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs index 8eeb1b21a95550..15d867a477bc54 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs @@ -15,11 +15,11 @@ namespace Microsoft.Interop public sealed class StringMarshallingInfoProvider : ITypeBasedMarshallingInfoProvider { private readonly Compilation _compilation; - private readonly IGeneratorDiagnostics _diagnostics; + private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; private readonly AttributeData _stringMarshallingCustomAttribute; private readonly DefaultMarshallingInfo _defaultMarshallingInfo; - public StringMarshallingInfoProvider(Compilation compilation, IGeneratorDiagnostics diagnostics, AttributeData stringMarshallingCustomAttribute, DefaultMarshallingInfo defaultMarshallingInfo) + public StringMarshallingInfoProvider(Compilation compilation, MarshallingInfoParserDiagnosticsBag diagnostics, AttributeData stringMarshallingCustomAttribute, DefaultMarshallingInfo defaultMarshallingInfo) { _compilation = compilation; _diagnostics = diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SymbolDiagnosticLocations.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SymbolDiagnosticLocations.cs new file mode 100644 index 00000000000000..02331348885a6d --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SymbolDiagnosticLocations.cs @@ -0,0 +1,50 @@ +// 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.Collections.Immutable; +using System.Linq; +using Microsoft.CodeAnalysis; + +namespace Microsoft.Interop +{ + public sealed class SymbolDiagnosticLocations + { + private SymbolDiagnosticLocations(string identifier, Location location) + { + Identifier = identifier; + IdentifierLocation = location; + } + + public string Identifier { get; init; } + + public Location IdentifierLocation { get; init; } + + public required ImmutableArray<(string FullyQualifiedName, Location Location)> AttributeLocations { get; init; } + + public bool Equals(SymbolDiagnosticLocations other) + { + return Identifier == other.Identifier + && AttributeLocations.SequenceEqual(other.AttributeLocations) + && IdentifierLocation.Equals(other.IdentifierLocation); + } + + public static SymbolDiagnosticLocations CreateForReturnType(IMethodSymbol symbol) + { + return new SymbolDiagnosticLocations(symbol.Name, symbol.Locations[0]) + { + AttributeLocations = symbol.GetReturnTypeAttributes().Select(a => (a.AttributeClass.ToDisplayString(), Location.Create(a.ApplicationSyntaxReference.SyntaxTree, a.ApplicationSyntaxReference.Span))).ToImmutableArray() + }; + } + + public static SymbolDiagnosticLocations Create(ISymbol symbol) + { + return new SymbolDiagnosticLocations(symbol.Name, symbol.Locations[0]) + { + AttributeLocations = symbol.GetAttributes().Select(a => (a.AttributeClass.ToDisplayString(), Location.Create(a.ApplicationSyntaxReference.SyntaxTree, a.ApplicationSyntaxReference.Span))).ToImmutableArray() + }; + } + + public override int GetHashCode() => throw new UnreachableException(); + } +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UseSiteAttributeProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UseSiteAttributeProvider.cs index fa19c1991e2627..ec4fb522d533fb 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UseSiteAttributeProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UseSiteAttributeProvider.cs @@ -15,7 +15,7 @@ public sealed class UseSiteAttributeProvider { private readonly ImmutableDictionary _useSiteAttributesByIndirectionDepth; private readonly int _maxIndirectionLevelDataProvided; - private readonly IGeneratorDiagnostics _diagnostics; + private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; private int _maxIndirectionLevelUsed; /// @@ -30,7 +30,7 @@ internal UseSiteAttributeProvider( ImmutableArray useSiteAttributeParsers, IEnumerable useSiteAttributes, IElementInfoProvider elementInfoProvider, - IGeneratorDiagnostics diagnostics, + MarshallingInfoParserDiagnosticsBag diagnostics, GetMarshallingInfoCallback getMarshallingInfoCallback) { ImmutableDictionary.Builder useSiteAttributesByIndirectionDepth = ImmutableDictionary.CreateBuilder(); diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/Diagnostics.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/Diagnostics.cs index 030ffba39431d8..aeb467e4bc77c3 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/Diagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/Diagnostics.cs @@ -144,10 +144,10 @@ partial class Test """; await VerifyCS.VerifySourceGeneratorAsync(source, - VerifyCS.Diagnostic(GeneratorDiagnostics.ParameterConfigurationNotSupported) + VerifyCS.Diagnostic(GeneratorDiagnostics.MarshalAsParameterConfigurationNotSupported) .WithLocation(0) .WithArguments(nameof(MarshalAsAttribute), "i1"), - VerifyCS.Diagnostic(GeneratorDiagnostics.ParameterConfigurationNotSupported) + VerifyCS.Diagnostic(GeneratorDiagnostics.MarshalAsParameterConfigurationNotSupported) .WithLocation(1) .WithArguments(nameof(MarshalAsAttribute), "b2")); } @@ -171,10 +171,10 @@ partial class Test """; await VerifyCS.VerifySourceGeneratorAsync(source, - VerifyCS.Diagnostic(GeneratorDiagnostics.ReturnConfigurationNotSupported) + VerifyCS.Diagnostic(GeneratorDiagnostics.MarshalAsReturnConfigurationNotSupported) .WithLocation(0) .WithArguments(nameof(MarshalAsAttribute), "Method1"), - VerifyCS.Diagnostic(GeneratorDiagnostics.ReturnConfigurationNotSupported) + VerifyCS.Diagnostic(GeneratorDiagnostics.MarshalAsReturnConfigurationNotSupported) .WithLocation(1) .WithArguments(nameof(MarshalAsAttribute), "Method2")); } @@ -200,13 +200,13 @@ await VerifyCS.VerifySourceGeneratorAsync(source, VerifyCS.Diagnostic(GeneratorDiagnostics.ConfigurationValueNotSupported) .WithLocation(0) .WithArguments(1, nameof(UnmanagedType)), - VerifyCS.Diagnostic(GeneratorDiagnostics.ReturnConfigurationNotSupported) + VerifyCS.Diagnostic(GeneratorDiagnostics.MarshalAsReturnConfigurationNotSupported) .WithLocation(1) .WithArguments(nameof(MarshalAsAttribute), "Method1"), VerifyCS.Diagnostic(GeneratorDiagnostics.ConfigurationValueNotSupported) .WithLocation(2) .WithArguments(0, nameof(UnmanagedType)), - VerifyCS.Diagnostic(GeneratorDiagnostics.ParameterConfigurationNotSupported) + VerifyCS.Diagnostic(GeneratorDiagnostics.MarshalAsParameterConfigurationNotSupported) .WithLocation(3) .WithArguments(nameof(MarshalAsAttribute), "b")); } From d76752f048b1b59526c75ae601b1e305ba02be15 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 15 Jun 2023 20:43:09 -0700 Subject: [PATCH 2/8] Fix formatting --- .../ByValueContentsMarshalKindValidator.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs index 991a0ebd35953a..a0be85bf50c324 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs @@ -39,7 +39,7 @@ private static ResolvedGenerator ValidateByValueMarshalKind(TypePositionInfo inf { Diagnostics = generator.Diagnostics.Add(new GeneratorDiagnostic.NotSupported(info, context) { - NotSupportedDetails = SR.InOutAttributeByRefNotSupported + NotSupportedDetails = SR.InOutAttributeByRefNotSupported }) }; } @@ -49,19 +49,19 @@ private static ResolvedGenerator ValidateByValueMarshalKind(TypePositionInfo inf { Diagnostics = generator.Diagnostics.Add(new GeneratorDiagnostic.NotSupported(info, context) { - NotSupportedDetails = SR.InAttributeNotSupportedWithoutOut + NotSupportedDetails = SR.InAttributeNotSupportedWithoutOut }) - }; - } - else if (info.ByValueContentsMarshalKind != ByValueContentsMarshalKind.Default) - && !generator.SupportsByValueMarshalKind(info.ByValueContentsMarshalKind, context)) - // TODO: Emit diagnostic for unnecesary attributes instead of failing the compilation. - return generator with + }; + } + else if (info.ByValueContentsMarshalKind != ByValueContentsMarshalKind.Default + && !generator.Generator.SupportsByValueMarshalKind(info.ByValueContentsMarshalKind, context)) { - Diagnostics = generator.Diagnostics.Add(new GeneratorDiagnostic.NotSupported(info, context) + return generator with { - NotSupportedDetails = SR.InOutAttributeMarshalerNotSupported - }) + Diagnostics = generator.Diagnostics.Add(new GeneratorDiagnostic.NotSupported(info, context) + { + NotSupportedDetails = SR.InOutAttributeMarshalerNotSupported + }) }; } return generator; From f57baac7b29cbbf16f80430c53656cb57ef6119f Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 16 Jun 2023 10:06:34 -0700 Subject: [PATCH 3/8] Collapse together the two different generator diagnostic bag types into one. --- .../JSImportGenerator/DescriptorProvider.cs | 7 +- .../JSImportGenerator/JSExportGenerator.cs | 19 +- .../JSImportGenerator/JSImportGenerator.cs | 15 +- .../JSImportGenerator/JSSignatureContext.cs | 2 +- .../System.Runtime.InteropServices.sln | 321 +++++++++--------- ...omImportToGeneratedComInterfaceAnalyzer.cs | 8 +- .../ComInterfaceGenerator.cs | 11 +- .../DiagnosticDescriptorProvider.cs | 7 +- .../GeneratorDiagnostics.cs | 4 +- .../ManagedToNativeVTableMethodGenerator.cs | 4 +- .../VirtualMethodPointerStubGenerator.cs | 17 +- .../VtableIndexStubGenerator.cs | 16 +- .../Common/DefaultMarshallingInfoParser.cs | 2 +- .../ConvertToLibraryImportAnalyzer.cs | 6 +- .../DiagnosticDescriptorProvider.cs | 7 +- .../GeneratorDiagnostics.cs | 4 +- .../LibraryImportGenerator.cs | 18 +- .../CustomMarshallingInfoHelper.cs | 4 +- ...gnosticsBag.cs => DiagnosticExtensions.cs} | 90 ----- .../GeneratorDiagnosticsBag.cs | 118 +++++++ .../MarshalAsAttributeParser.cs | 4 +- .../MarshalUsingAttributeParser.cs | 4 +- .../MarshallingInfoParser.cs | 8 +- .../MethodSignatureDiagnosticLocations.cs | 30 +- .../MethodSignatureElementInfoProvider.cs | 4 +- .../NativeMarshallingAttributeParser.cs | 4 +- .../StringMarshallingInfoProvider.cs | 4 +- .../UseSiteAttributeProvider.cs | 4 +- 28 files changed, 393 insertions(+), 349 deletions(-) rename src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/{MarshallingInfoParserDiagnosticsBag.cs => DiagnosticExtensions.cs} (64%) create mode 100644 src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratorDiagnosticsBag.cs diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/DescriptorProvider.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/DescriptorProvider.cs index 0db6708469b374..c72ca2e7e2cf19 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/DescriptorProvider.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/DescriptorProvider.cs @@ -9,14 +9,17 @@ internal sealed class DescriptorProvider : IDiagnosticDescriptorProvider { public DiagnosticDescriptor InvalidMarshallingAttributeInfo => GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported; - public DiagnosticDescriptor GetConfigurationNotSupportedDescriptor(bool withValue) => withValue ? GeneratorDiagnostics.ConfigurationValueNotSupported : GeneratorDiagnostics.ConfigurationNotSupported; + public DiagnosticDescriptor ConfigurationNotSupported => GeneratorDiagnostics.ConfigurationNotSupported; - public DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic) + public DiagnosticDescriptor ConfigurationValueNotSupported => GeneratorDiagnostics.ConfigurationValueNotSupported; + + public DiagnosticDescriptor? GetDescriptor(GeneratorDiagnostic diagnostic) { return diagnostic switch { GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, + { IsFatal: false } => null, // The JSImport and JSExport generators don't report any non-fatal diagnostics. { TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupported, { TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupported, }; diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs index 8ae94cf87d7635..dccd4d36c44de4 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs @@ -189,20 +189,20 @@ private static IncrementalStubGenerationContext CalculateStubInformation( Debug.Assert(jsExportAttr is not null); - var generatorDiagnostics = new GeneratorDiagnosticBag(); - var descriptorProvider = new DescriptorProvider(); + var locations = new MethodSignatureDiagnosticLocations(originalSyntax); + var generatorDiagnostics = new GeneratorDiagnosticsBag(new DescriptorProvider(), locations, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); // Process the JSExport attribute JSExportData? jsExportData = ProcessJSExportAttribute(jsExportAttr!); if (jsExportData is null) { - generatorDiagnostics.ReportConfigurationNotSupported(descriptorProvider, jsExportAttr!, "Invalid syntax"); + generatorDiagnostics.ReportConfigurationNotSupported(jsExportAttr!, "Invalid syntax"); jsExportData = new JSExportData(); } // Create the stub. - var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(descriptorProvider, generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); + var marshallingInfoParserDiagnosticBag = var signatureContext = JSSignatureContext.Create(symbol, environment, marshallingInfoParserDiagnosticBag, ct); var containingTypeContext = new ContainingSyntaxContext(originalSyntax); @@ -213,7 +213,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation( signatureContext, containingTypeContext, methodSyntaxTemplate, - new MethodSignatureDiagnosticLocations(originalSyntax), + locations, jsExportData, CreateGeneratorFactory(environment, options), new SequenceEqualImmutableArray(generatorDiagnostics.Diagnostics.ToImmutableArray())); @@ -291,9 +291,7 @@ private static NamespaceDeclarationSyntax GenerateRegSource( private static (MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray) GenerateSource( IncrementalStubGenerationContext incrementalContext) { - var diagnostics = new GeneratorDiagnosticBag(); - - var descriptorProvider = new DescriptorProvider(); + var diagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), incrementalContext.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); // Generate stub code var stubGenerator = new JSExportCodeGenerator( @@ -302,10 +300,7 @@ private static (MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, I incrementalContext.SignatureContext.SignatureContext.ElementTypeInformation, incrementalContext.JSExportData, incrementalContext.SignatureContext, - ex => - { - diagnostics.ReportGeneratorDiagnostic(descriptorProvider, incrementalContext.DiagnosticLocation, ex); - }, + diagnostics.ReportGeneratorDiagnostic, incrementalContext.GeneratorFactoryKey.GeneratorFactory); var wrapperName = "__Wrapper_" + incrementalContext.StubMethodSyntaxTemplate.Identifier + "_" + incrementalContext.SignatureContext.TypesHash; diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs index 6a16632745011d..4970cd7dddb724 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs @@ -177,22 +177,20 @@ private static IncrementalStubGenerationContext CalculateStubInformation( Debug.Assert(jsImportAttr is not null); - var generatorDiagnostics = new GeneratorDiagnosticBag(); - var descriptorProvider = new DescriptorProvider(); + var locations = new MethodSignatureDiagnosticLocations(originalSyntax); + var diagnosticsBag = new GeneratorDiagnosticsBag(new DescriptorProvider(), locations, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); // Process the JSImport attribute JSImportData? jsImportData = ProcessJSImportAttribute(jsImportAttr!); if (jsImportData is null) { - generatorDiagnostics.ReportConfigurationNotSupported(descriptorProvider, jsImportAttr!, "Invalid syntax"); + generatorDiagnostics.ReportConfigurationNotSupported(jsImportAttr!, "Invalid syntax"); jsImportData = new JSImportData("INVALID_CSHARP_SYNTAX", null); } // Create the stub. - - var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(descriptorProvider, generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); - var signatureContext = JSSignatureContext.Create(symbol, environment, marshallingInfoParserDiagnosticBag, ct); + var signatureContext = JSSignatureContext.Create(symbol, environment, diagnosticsBag, ct); var containingTypeContext = new ContainingSyntaxContext(originalSyntax); @@ -201,7 +199,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation( signatureContext, containingTypeContext, methodSyntaxTemplate, - new MethodSignatureDiagnosticLocations(originalSyntax), + , jsImportData, CreateGeneratorFactory(environment, options), new SequenceEqualImmutableArray(generatorDiagnostics.Diagnostics.ToImmutableArray())); @@ -217,8 +215,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation( private static (MemberDeclarationSyntax, ImmutableArray) GenerateSource( IncrementalStubGenerationContext incrementalContext) { - var diagnostics = new GeneratorDiagnosticBag(); - var descriptorProvider = new DescriptorProvider(); + var diagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), incrementalContext.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); // Generate stub code var stubGenerator = new JSImportCodeGenerator( diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSSignatureContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSSignatureContext.cs index 54f839b517b1f7..349cf884e551bd 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSSignatureContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSSignatureContext.cs @@ -29,7 +29,7 @@ internal sealed record JSSignatureContext public static JSSignatureContext Create( IMethodSymbol method, StubEnvironment env, - MarshallingInfoParserDiagnosticsBag diagnostics, + GeneratorDiagnosticsBag diagnostics, CancellationToken token) { // Cancel early if requested diff --git a/src/libraries/System.Runtime.InteropServices/System.Runtime.InteropServices.sln b/src/libraries/System.Runtime.InteropServices/System.Runtime.InteropServices.sln index 949db1c9715341..1bf3d501dabe44 100644 --- a/src/libraries/System.Runtime.InteropServices/System.Runtime.InteropServices.sln +++ b/src/libraries/System.Runtime.InteropServices/System.Runtime.InteropServices.sln @@ -1,4 +1,8 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.33711.456 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.CoreLib", "..\..\coreclr\System.Private.CoreLib\System.Private.CoreLib.csproj", "{94B59BA0-491F-4B59-ADFF-A057EC3EC835}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}" @@ -63,6 +67,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "gen", "{E1AEBD5D-AE4 EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Checked|Any CPU = Checked|Any CPU + Checked|arm = Checked|arm + Checked|arm64 = Checked|arm64 + Checked|x64 = Checked|x64 + Checked|x86 = Checked|x86 Debug|Any CPU = Debug|Any CPU Debug|arm = Debug|arm Debug|arm64 = Debug|arm64 @@ -73,13 +82,18 @@ Global Release|arm64 = Release|arm64 Release|x64 = Release|x64 Release|x86 = Release|x86 - Checked|Any CPU = Checked|Any CPU - Checked|arm = Checked|arm - Checked|arm64 = Checked|arm64 - Checked|x64 = Checked|x64 - Checked|x86 = Checked|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|Any CPU.ActiveCfg = Checked|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|Any CPU.Build.0 = Checked|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|arm.ActiveCfg = Checked|arm + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|arm.Build.0 = Checked|arm + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|arm64.ActiveCfg = Checked|arm64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|arm64.Build.0 = Checked|arm64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x64.ActiveCfg = Checked|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x64.Build.0 = Checked|x64 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x86.ActiveCfg = Checked|x86 + {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x86.Build.0 = Checked|x86 {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Debug|Any CPU.ActiveCfg = Debug|x64 {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Debug|Any CPU.Build.0 = Debug|x64 {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Debug|arm.ActiveCfg = Debug|arm @@ -100,16 +114,11 @@ Global {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Release|x64.Build.0 = Release|x64 {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Release|x86.ActiveCfg = Release|x86 {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Release|x86.Build.0 = Release|x86 - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|Any CPU.ActiveCfg = Checked|x64 - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|Any CPU.Build.0 = Checked|x64 - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|arm.ActiveCfg = Checked|arm - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|arm.Build.0 = Checked|arm - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|arm64.ActiveCfg = Checked|arm64 - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|arm64.Build.0 = Checked|arm64 - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x64.ActiveCfg = Checked|x64 - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x64.Build.0 = Checked|x64 - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x86.ActiveCfg = Checked|x86 - {94B59BA0-491F-4B59-ADFF-A057EC3EC835}.Checked|x86.Build.0 = Checked|x86 + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|arm.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|arm64.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|x64.ActiveCfg = Debug|Any CPU + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|x86.ActiveCfg = Debug|Any CPU {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Debug|Any CPU.Build.0 = Debug|Any CPU {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -126,11 +135,11 @@ Global {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Release|x64.Build.0 = Release|Any CPU {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Release|x86.ActiveCfg = Release|Any CPU {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Release|x86.Build.0 = Release|Any CPU - {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|arm.ActiveCfg = Debug|Any CPU - {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|arm64.ActiveCfg = Debug|Any CPU - {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|x64.ActiveCfg = Debug|Any CPU - {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA}.Checked|x86.ActiveCfg = Debug|Any CPU + {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|arm.ActiveCfg = Debug|Any CPU + {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|arm64.ActiveCfg = Debug|Any CPU + {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|x64.ActiveCfg = Debug|Any CPU + {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|x86.ActiveCfg = Debug|Any CPU {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Debug|Any CPU.Build.0 = Debug|Any CPU {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -147,11 +156,11 @@ Global {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Release|x64.Build.0 = Release|Any CPU {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Release|x86.ActiveCfg = Release|Any CPU {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Release|x86.Build.0 = Release|Any CPU - {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|arm.ActiveCfg = Debug|Any CPU - {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|arm64.ActiveCfg = Debug|Any CPU - {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|x64.ActiveCfg = Debug|Any CPU - {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0}.Checked|x86.ActiveCfg = Debug|Any CPU + {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|arm.ActiveCfg = Debug|Any CPU + {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|arm64.ActiveCfg = Debug|Any CPU + {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|x64.ActiveCfg = Debug|Any CPU + {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|x86.ActiveCfg = Debug|Any CPU {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Debug|Any CPU.Build.0 = Debug|Any CPU {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -168,11 +177,11 @@ Global {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Release|x64.Build.0 = Release|Any CPU {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Release|x86.ActiveCfg = Release|Any CPU {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Release|x86.Build.0 = Release|Any CPU - {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|arm.ActiveCfg = Debug|Any CPU - {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|arm64.ActiveCfg = Debug|Any CPU - {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|x64.ActiveCfg = Debug|Any CPU - {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69}.Checked|x86.ActiveCfg = Debug|Any CPU + {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|arm.ActiveCfg = Debug|Any CPU + {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|arm64.ActiveCfg = Debug|Any CPU + {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|x64.ActiveCfg = Debug|Any CPU + {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|x86.ActiveCfg = Debug|Any CPU {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Debug|Any CPU.Build.0 = Debug|Any CPU {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -189,11 +198,11 @@ Global {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Release|x64.Build.0 = Release|Any CPU {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Release|x86.ActiveCfg = Release|Any CPU {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Release|x86.Build.0 = Release|Any CPU - {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|arm.ActiveCfg = Debug|Any CPU - {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|arm64.ActiveCfg = Debug|Any CPU - {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|x64.ActiveCfg = Debug|Any CPU - {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A}.Checked|x86.ActiveCfg = Debug|Any CPU + {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|arm.ActiveCfg = Debug|Any CPU + {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|arm64.ActiveCfg = Debug|Any CPU + {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|x64.ActiveCfg = Debug|Any CPU + {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|x86.ActiveCfg = Debug|Any CPU {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Debug|Any CPU.Build.0 = Debug|Any CPU {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -210,11 +219,11 @@ Global {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Release|x64.Build.0 = Release|Any CPU {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Release|x86.ActiveCfg = Release|Any CPU {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Release|x86.Build.0 = Release|Any CPU - {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|arm.ActiveCfg = Debug|Any CPU - {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|arm64.ActiveCfg = Debug|Any CPU - {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|x64.ActiveCfg = Debug|Any CPU - {C4B641C3-3317-4913-91DA-0DA3B64BABED}.Checked|x86.ActiveCfg = Debug|Any CPU + {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|arm.ActiveCfg = Debug|Any CPU + {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|arm64.ActiveCfg = Debug|Any CPU + {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|x64.ActiveCfg = Debug|Any CPU + {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|x86.ActiveCfg = Debug|Any CPU {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Debug|Any CPU.Build.0 = Debug|Any CPU {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -231,11 +240,11 @@ Global {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Release|x64.Build.0 = Release|Any CPU {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Release|x86.ActiveCfg = Release|Any CPU {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Release|x86.Build.0 = Release|Any CPU - {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|arm.ActiveCfg = Debug|Any CPU - {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|arm64.ActiveCfg = Debug|Any CPU - {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|x64.ActiveCfg = Debug|Any CPU - {3FB6F2AA-E763-4336-B927-18AB7AAF6C20}.Checked|x86.ActiveCfg = Debug|Any CPU + {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|arm.ActiveCfg = Debug|Any CPU + {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|arm64.ActiveCfg = Debug|Any CPU + {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|x64.ActiveCfg = Debug|Any CPU + {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|x86.ActiveCfg = Debug|Any CPU {716ED44B-37C8-4776-BE70-285952D2B30D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {716ED44B-37C8-4776-BE70-285952D2B30D}.Debug|Any CPU.Build.0 = Debug|Any CPU {716ED44B-37C8-4776-BE70-285952D2B30D}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -252,11 +261,11 @@ Global {716ED44B-37C8-4776-BE70-285952D2B30D}.Release|x64.Build.0 = Release|Any CPU {716ED44B-37C8-4776-BE70-285952D2B30D}.Release|x86.ActiveCfg = Release|Any CPU {716ED44B-37C8-4776-BE70-285952D2B30D}.Release|x86.Build.0 = Release|Any CPU - {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|arm.ActiveCfg = Debug|Any CPU - {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|arm64.ActiveCfg = Debug|Any CPU - {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|x64.ActiveCfg = Debug|Any CPU - {716ED44B-37C8-4776-BE70-285952D2B30D}.Checked|x86.ActiveCfg = Debug|Any CPU + {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|arm.ActiveCfg = Debug|Any CPU + {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|arm64.ActiveCfg = Debug|Any CPU + {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|x64.ActiveCfg = Debug|Any CPU + {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|x86.ActiveCfg = Debug|Any CPU {1B248B4C-7584-4C04-850A-A50EB592052C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1B248B4C-7584-4C04-850A-A50EB592052C}.Debug|Any CPU.Build.0 = Debug|Any CPU {1B248B4C-7584-4C04-850A-A50EB592052C}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -273,11 +282,11 @@ Global {1B248B4C-7584-4C04-850A-A50EB592052C}.Release|x64.Build.0 = Release|Any CPU {1B248B4C-7584-4C04-850A-A50EB592052C}.Release|x86.ActiveCfg = Release|Any CPU {1B248B4C-7584-4C04-850A-A50EB592052C}.Release|x86.Build.0 = Release|Any CPU - {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|arm.ActiveCfg = Debug|Any CPU - {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|arm64.ActiveCfg = Debug|Any CPU - {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|x64.ActiveCfg = Debug|Any CPU - {1B248B4C-7584-4C04-850A-A50EB592052C}.Checked|x86.ActiveCfg = Debug|Any CPU + {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|arm.ActiveCfg = Debug|Any CPU + {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|arm64.ActiveCfg = Debug|Any CPU + {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|x64.ActiveCfg = Debug|Any CPU + {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|x86.ActiveCfg = Debug|Any CPU {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Debug|Any CPU.Build.0 = Debug|Any CPU {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -294,11 +303,11 @@ Global {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Release|x64.Build.0 = Release|Any CPU {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Release|x86.ActiveCfg = Release|Any CPU {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Release|x86.Build.0 = Release|Any CPU - {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|arm.ActiveCfg = Debug|Any CPU - {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|arm64.ActiveCfg = Debug|Any CPU - {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|x64.ActiveCfg = Debug|Any CPU - {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886}.Checked|x86.ActiveCfg = Debug|Any CPU + {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|arm.ActiveCfg = Debug|Any CPU + {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|arm64.ActiveCfg = Debug|Any CPU + {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|x64.ActiveCfg = Debug|Any CPU + {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|x86.ActiveCfg = Debug|Any CPU {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Debug|Any CPU.Build.0 = Debug|Any CPU {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -315,11 +324,11 @@ Global {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Release|x64.Build.0 = Release|Any CPU {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Release|x86.ActiveCfg = Release|Any CPU {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Release|x86.Build.0 = Release|Any CPU - {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|arm.ActiveCfg = Debug|Any CPU - {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|arm64.ActiveCfg = Debug|Any CPU - {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|x64.ActiveCfg = Debug|Any CPU - {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5}.Checked|x86.ActiveCfg = Debug|Any CPU + {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|arm.ActiveCfg = Debug|Any CPU + {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|arm64.ActiveCfg = Debug|Any CPU + {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|x64.ActiveCfg = Debug|Any CPU + {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|x86.ActiveCfg = Debug|Any CPU {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Debug|Any CPU.Build.0 = Debug|Any CPU {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -336,11 +345,11 @@ Global {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Release|x64.Build.0 = Release|Any CPU {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Release|x86.ActiveCfg = Release|Any CPU {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Release|x86.Build.0 = Release|Any CPU - {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|arm.ActiveCfg = Debug|Any CPU - {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|arm64.ActiveCfg = Debug|Any CPU - {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|x64.ActiveCfg = Debug|Any CPU - {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40}.Checked|x86.ActiveCfg = Debug|Any CPU + {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|arm.ActiveCfg = Debug|Any CPU + {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|arm64.ActiveCfg = Debug|Any CPU + {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|x64.ActiveCfg = Debug|Any CPU + {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|x86.ActiveCfg = Debug|Any CPU {768B77B0-EA45-469D-B39E-545EB72F5A43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {768B77B0-EA45-469D-B39E-545EB72F5A43}.Debug|Any CPU.Build.0 = Debug|Any CPU {768B77B0-EA45-469D-B39E-545EB72F5A43}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -357,11 +366,11 @@ Global {768B77B0-EA45-469D-B39E-545EB72F5A43}.Release|x64.Build.0 = Release|Any CPU {768B77B0-EA45-469D-B39E-545EB72F5A43}.Release|x86.ActiveCfg = Release|Any CPU {768B77B0-EA45-469D-B39E-545EB72F5A43}.Release|x86.Build.0 = Release|Any CPU - {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|arm.ActiveCfg = Debug|Any CPU - {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|arm64.ActiveCfg = Debug|Any CPU - {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|x64.ActiveCfg = Debug|Any CPU - {768B77B0-EA45-469D-B39E-545EB72F5A43}.Checked|x86.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|arm.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|arm64.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|x64.ActiveCfg = Debug|Any CPU + {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|x86.ActiveCfg = Debug|Any CPU {8671F164-F78C-44FA-93B7-A310F67890FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8671F164-F78C-44FA-93B7-A310F67890FE}.Debug|Any CPU.Build.0 = Debug|Any CPU {8671F164-F78C-44FA-93B7-A310F67890FE}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -378,11 +387,11 @@ Global {8671F164-F78C-44FA-93B7-A310F67890FE}.Release|x64.Build.0 = Release|Any CPU {8671F164-F78C-44FA-93B7-A310F67890FE}.Release|x86.ActiveCfg = Release|Any CPU {8671F164-F78C-44FA-93B7-A310F67890FE}.Release|x86.Build.0 = Release|Any CPU - {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|arm.ActiveCfg = Debug|Any CPU - {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|arm64.ActiveCfg = Debug|Any CPU - {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|x64.ActiveCfg = Debug|Any CPU - {8671F164-F78C-44FA-93B7-A310F67890FE}.Checked|x86.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|arm.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|arm64.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|x64.ActiveCfg = Debug|Any CPU + {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|x86.ActiveCfg = Debug|Any CPU {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Debug|Any CPU.Build.0 = Debug|Any CPU {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -399,11 +408,11 @@ Global {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Release|x64.Build.0 = Release|Any CPU {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Release|x86.ActiveCfg = Release|Any CPU {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Release|x86.Build.0 = Release|Any CPU - {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|arm.ActiveCfg = Debug|Any CPU - {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|arm64.ActiveCfg = Debug|Any CPU - {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|x64.ActiveCfg = Debug|Any CPU - {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1}.Checked|x86.ActiveCfg = Debug|Any CPU + {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|arm.ActiveCfg = Debug|Any CPU + {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|arm64.ActiveCfg = Debug|Any CPU + {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|x64.ActiveCfg = Debug|Any CPU + {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|x86.ActiveCfg = Debug|Any CPU {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Debug|Any CPU.Build.0 = Debug|Any CPU {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -420,11 +429,11 @@ Global {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Release|x64.Build.0 = Release|Any CPU {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Release|x86.ActiveCfg = Release|Any CPU {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Release|x86.Build.0 = Release|Any CPU - {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|arm.ActiveCfg = Debug|Any CPU - {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|arm64.ActiveCfg = Debug|Any CPU - {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|x64.ActiveCfg = Debug|Any CPU - {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E}.Checked|x86.ActiveCfg = Debug|Any CPU + {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|arm.ActiveCfg = Debug|Any CPU + {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|arm64.ActiveCfg = Debug|Any CPU + {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|x64.ActiveCfg = Debug|Any CPU + {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|x86.ActiveCfg = Debug|Any CPU {3741C833-C364-4269-9B1D-D442055DA7CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3741C833-C364-4269-9B1D-D442055DA7CE}.Debug|Any CPU.Build.0 = Debug|Any CPU {3741C833-C364-4269-9B1D-D442055DA7CE}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -441,11 +450,11 @@ Global {3741C833-C364-4269-9B1D-D442055DA7CE}.Release|x64.Build.0 = Release|Any CPU {3741C833-C364-4269-9B1D-D442055DA7CE}.Release|x86.ActiveCfg = Release|Any CPU {3741C833-C364-4269-9B1D-D442055DA7CE}.Release|x86.Build.0 = Release|Any CPU - {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|arm.ActiveCfg = Debug|Any CPU - {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|arm64.ActiveCfg = Debug|Any CPU - {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|x64.ActiveCfg = Debug|Any CPU - {3741C833-C364-4269-9B1D-D442055DA7CE}.Checked|x86.ActiveCfg = Debug|Any CPU + {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|arm.ActiveCfg = Debug|Any CPU + {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|arm64.ActiveCfg = Debug|Any CPU + {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|x64.ActiveCfg = Debug|Any CPU + {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|x86.ActiveCfg = Debug|Any CPU {1D771995-D475-429B-AC31-2B1F618AA45F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1D771995-D475-429B-AC31-2B1F618AA45F}.Debug|Any CPU.Build.0 = Debug|Any CPU {1D771995-D475-429B-AC31-2B1F618AA45F}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -462,11 +471,11 @@ Global {1D771995-D475-429B-AC31-2B1F618AA45F}.Release|x64.Build.0 = Release|Any CPU {1D771995-D475-429B-AC31-2B1F618AA45F}.Release|x86.ActiveCfg = Release|Any CPU {1D771995-D475-429B-AC31-2B1F618AA45F}.Release|x86.Build.0 = Release|Any CPU - {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|arm.ActiveCfg = Debug|Any CPU - {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|arm64.ActiveCfg = Debug|Any CPU - {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|x64.ActiveCfg = Debug|Any CPU - {1D771995-D475-429B-AC31-2B1F618AA45F}.Checked|x86.ActiveCfg = Debug|Any CPU + {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|arm.ActiveCfg = Debug|Any CPU + {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|arm64.ActiveCfg = Debug|Any CPU + {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|x64.ActiveCfg = Debug|Any CPU + {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|x86.ActiveCfg = Debug|Any CPU {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Debug|Any CPU.Build.0 = Debug|Any CPU {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -483,11 +492,11 @@ Global {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Release|x64.Build.0 = Release|Any CPU {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Release|x86.ActiveCfg = Release|Any CPU {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Release|x86.Build.0 = Release|Any CPU - {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|arm.ActiveCfg = Debug|Any CPU - {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|arm64.ActiveCfg = Debug|Any CPU - {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|x64.ActiveCfg = Debug|Any CPU - {9C2C2B5C-5E75-4935-8A4A-DE3D3A5DBBC1}.Checked|x86.ActiveCfg = Debug|Any CPU + {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|arm.ActiveCfg = Debug|Any CPU + {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|arm64.ActiveCfg = Debug|Any CPU + {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|x64.ActiveCfg = Debug|Any CPU + {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|x86.ActiveCfg = Debug|Any CPU {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Debug|Any CPU.Build.0 = Debug|Any CPU {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -504,11 +513,11 @@ Global {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Release|x64.Build.0 = Release|Any CPU {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Release|x86.ActiveCfg = Release|Any CPU {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Release|x86.Build.0 = Release|Any CPU - {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|arm.ActiveCfg = Debug|Any CPU - {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|arm64.ActiveCfg = Debug|Any CPU - {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|x64.ActiveCfg = Debug|Any CPU - {EA8DBC12-60BC-433E-ABFF-A89DFA795283}.Checked|x86.ActiveCfg = Debug|Any CPU + {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|arm.ActiveCfg = Debug|Any CPU + {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|arm64.ActiveCfg = Debug|Any CPU + {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|x64.ActiveCfg = Debug|Any CPU + {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|x86.ActiveCfg = Debug|Any CPU {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Debug|Any CPU.Build.0 = Debug|Any CPU {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -525,11 +534,11 @@ Global {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Release|x64.Build.0 = Release|Any CPU {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Release|x86.ActiveCfg = Release|Any CPU {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Release|x86.Build.0 = Release|Any CPU - {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|arm.ActiveCfg = Debug|Any CPU - {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|arm64.ActiveCfg = Debug|Any CPU - {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|x64.ActiveCfg = Debug|Any CPU - {25D66424-2EAF-464D-8460-10C04EDEF3C3}.Checked|x86.ActiveCfg = Debug|Any CPU + {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|arm.ActiveCfg = Debug|Any CPU + {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|arm64.ActiveCfg = Debug|Any CPU + {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|x64.ActiveCfg = Debug|Any CPU + {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|x86.ActiveCfg = Debug|Any CPU {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Debug|Any CPU.Build.0 = Debug|Any CPU {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -546,11 +555,11 @@ Global {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Release|x64.Build.0 = Release|Any CPU {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Release|x86.ActiveCfg = Release|Any CPU {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Release|x86.Build.0 = Release|Any CPU - {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|arm.ActiveCfg = Debug|Any CPU - {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|arm64.ActiveCfg = Debug|Any CPU - {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|x64.ActiveCfg = Debug|Any CPU - {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF}.Checked|x86.ActiveCfg = Debug|Any CPU + {866D295E-424A-4747-9417-CD7746936138}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {866D295E-424A-4747-9417-CD7746936138}.Checked|arm.ActiveCfg = Debug|Any CPU + {866D295E-424A-4747-9417-CD7746936138}.Checked|arm64.ActiveCfg = Debug|Any CPU + {866D295E-424A-4747-9417-CD7746936138}.Checked|x64.ActiveCfg = Debug|Any CPU + {866D295E-424A-4747-9417-CD7746936138}.Checked|x86.ActiveCfg = Debug|Any CPU {866D295E-424A-4747-9417-CD7746936138}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {866D295E-424A-4747-9417-CD7746936138}.Debug|Any CPU.Build.0 = Debug|Any CPU {866D295E-424A-4747-9417-CD7746936138}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -567,11 +576,11 @@ Global {866D295E-424A-4747-9417-CD7746936138}.Release|x64.Build.0 = Release|Any CPU {866D295E-424A-4747-9417-CD7746936138}.Release|x86.ActiveCfg = Release|Any CPU {866D295E-424A-4747-9417-CD7746936138}.Release|x86.Build.0 = Release|Any CPU - {866D295E-424A-4747-9417-CD7746936138}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {866D295E-424A-4747-9417-CD7746936138}.Checked|arm.ActiveCfg = Debug|Any CPU - {866D295E-424A-4747-9417-CD7746936138}.Checked|arm64.ActiveCfg = Debug|Any CPU - {866D295E-424A-4747-9417-CD7746936138}.Checked|x64.ActiveCfg = Debug|Any CPU - {866D295E-424A-4747-9417-CD7746936138}.Checked|x86.ActiveCfg = Debug|Any CPU + {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|arm.ActiveCfg = Debug|Any CPU + {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|arm64.ActiveCfg = Debug|Any CPU + {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|x64.ActiveCfg = Debug|Any CPU + {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|x86.ActiveCfg = Debug|Any CPU {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Debug|Any CPU.Build.0 = Debug|Any CPU {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -588,11 +597,11 @@ Global {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Release|x64.Build.0 = Release|Any CPU {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Release|x86.ActiveCfg = Release|Any CPU {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Release|x86.Build.0 = Release|Any CPU - {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|arm.ActiveCfg = Debug|Any CPU - {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|arm64.ActiveCfg = Debug|Any CPU - {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|x64.ActiveCfg = Debug|Any CPU - {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5}.Checked|x86.ActiveCfg = Debug|Any CPU + {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|arm.ActiveCfg = Debug|Any CPU + {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|arm64.ActiveCfg = Debug|Any CPU + {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|x64.ActiveCfg = Debug|Any CPU + {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|x86.ActiveCfg = Debug|Any CPU {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Debug|Any CPU.Build.0 = Debug|Any CPU {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -609,11 +618,11 @@ Global {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Release|x64.Build.0 = Release|Any CPU {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Release|x86.ActiveCfg = Release|Any CPU {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Release|x86.Build.0 = Release|Any CPU - {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|arm.ActiveCfg = Debug|Any CPU - {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|arm64.ActiveCfg = Debug|Any CPU - {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|x64.ActiveCfg = Debug|Any CPU - {0B5FD0C2-367D-4AD6-8001-80AD79B2441C}.Checked|x86.ActiveCfg = Debug|Any CPU + {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|arm.ActiveCfg = Debug|Any CPU + {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|arm64.ActiveCfg = Debug|Any CPU + {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|x64.ActiveCfg = Debug|Any CPU + {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|x86.ActiveCfg = Debug|Any CPU {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Debug|Any CPU.Build.0 = Debug|Any CPU {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -630,11 +639,11 @@ Global {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Release|x64.Build.0 = Release|Any CPU {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Release|x86.ActiveCfg = Release|Any CPU {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Release|x86.Build.0 = Release|Any CPU - {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|arm.ActiveCfg = Debug|Any CPU - {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|arm64.ActiveCfg = Debug|Any CPU - {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|x64.ActiveCfg = Debug|Any CPU - {C7DAC270-CC93-4C97-9A8D-6E724A10727D}.Checked|x86.ActiveCfg = Debug|Any CPU + {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|arm.ActiveCfg = Debug|Any CPU + {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|arm64.ActiveCfg = Debug|Any CPU + {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|x64.ActiveCfg = Debug|Any CPU + {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|x86.ActiveCfg = Debug|Any CPU {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Debug|Any CPU.Build.0 = Debug|Any CPU {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Debug|arm.ActiveCfg = Debug|Any CPU @@ -651,23 +660,26 @@ Global {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Release|x64.Build.0 = Release|Any CPU {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Release|x86.ActiveCfg = Release|Any CPU {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Release|x86.Build.0 = Release|Any CPU - {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|arm.ActiveCfg = Debug|Any CPU - {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|arm64.ActiveCfg = Debug|Any CPU - {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|x64.ActiveCfg = Debug|Any CPU - {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82}.Checked|x86.ActiveCfg = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {94B59BA0-491F-4B59-ADFF-A057EC3EC835} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} + {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} + {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} {F552E4E4-20EE-484C-84F8-4FB3A3BD2E69} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} + {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} {C4B641C3-3317-4913-91DA-0DA3B64BABED} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} + {3FB6F2AA-E763-4336-B927-18AB7AAF6C20} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} {716ED44B-37C8-4776-BE70-285952D2B30D} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} + {1B248B4C-7584-4C04-850A-A50EB592052C} = {E1AEBD5D-AE4E-4F61-B9ED-AEF950B0CC33} + {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} + {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5} = {E1AEBD5D-AE4E-4F61-B9ED-AEF950B0CC33} + {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40} = {E1AEBD5D-AE4E-4F61-B9ED-AEF950B0CC33} + {768B77B0-EA45-469D-B39E-545EB72F5A43} = {E1AEBD5D-AE4E-4F61-B9ED-AEF950B0CC33} + {8671F164-F78C-44FA-93B7-A310F67890FE} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} {4FC33B9B-1BCF-4D16-B886-DCA8F2B823C1} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} - {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} - {1FF4CC8E-49C3-42A0-A6E0-2E5908455FBA} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} {79F7BE0E-01AA-4AFB-B047-CF7C0B38F81E} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} {3741C833-C364-4269-9B1D-D442055DA7CE} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} {1D771995-D475-429B-AC31-2B1F618AA45F} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} @@ -677,19 +689,14 @@ Global {049B7FD4-ACEF-4BCD-A7A7-75C9BBEC4EBF} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} {866D295E-424A-4747-9417-CD7746936138} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} {D3A329E3-0FEB-4136-9CB6-B38319B0FFA5} = {FB99AC59-1744-4F12-A4B0-0D54FCA048BF} - {0E0D5A1F-0212-4CEB-BADA-E1E3ABD395A0} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} - {4859BEE3-34B7-48E7-83D4-1ADD8B8F3B3A} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} - {3FB6F2AA-E763-4336-B927-18AB7AAF6C20} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} - {EF39CC5C-7A3B-40F2-82B6-C1C8BBC3F886} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} - {8671F164-F78C-44FA-93B7-A310F67890FE} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} {0B5FD0C2-367D-4AD6-8001-80AD79B2441C} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} {C7DAC270-CC93-4C97-9A8D-6E724A10727D} = {D893B9AA-57C5-49E3-97B1-12CC62D84307} - {1B248B4C-7584-4C04-850A-A50EB592052C} = {E1AEBD5D-AE4E-4F61-B9ED-AEF950B0CC33} - {C3EA0A28-A597-4946-9E08-EBBBFA94BFA5} = {E1AEBD5D-AE4E-4F61-B9ED-AEF950B0CC33} - {90CDAD9F-3ACC-43B0-9696-0C849FCD8C40} = {E1AEBD5D-AE4E-4F61-B9ED-AEF950B0CC33} - {768B77B0-EA45-469D-B39E-545EB72F5A43} = {E1AEBD5D-AE4E-4F61-B9ED-AEF950B0CC33} + {C9B349C8-7B11-4DE4-A4BB-8D957A1D2A82} = {B1678CCD-95C8-4419-B9F9-14A03061BE4B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D4031401-FEB5-4CCF-91C1-38F5646B2BFD} EndGlobalSection + GlobalSection(SharedMSBuildProjectFiles) = preSolution + ..\System.Private.CoreLib\src\System.Private.CoreLib.Shared.projitems*{94b59ba0-491f-4b59-adff-a057ec3ec835}*SharedItemsImports = 5 + EndGlobalSection EndGlobal diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs index b183b32d970da9..d264dcfda5af58 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Runtime.InteropServices; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.DotnetRuntime.Extensions; using static Microsoft.Interop.Analyzers.AnalyzerDiagnostics; @@ -74,12 +75,11 @@ public override void Initialize(AnalysisContext context) // Use the method signature to do some of the work the generator will do after conversion. // If any diagnostics or failures to marshal are reported, then mark this diagnostic with a property signifying that it may require // later user work. - GeneratorDiagnosticBag diagnostics = new(); - MarshallingInfoParserDiagnosticsBag parserDiagnostics = new(new DiagnosticDescriptorProvider(), diagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); + GeneratorDiagnosticsBag diagnostics = new(new DiagnosticDescriptorProvider(), new MethodSignatureDiagnosticLocations((MethodDeclarationSyntax)method.DeclaringSyntaxReferences[0].GetSyntax()), SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); AttributeData comImportAttribute = type.GetAttributes().First(attr => attr.AttributeClass.ToDisplayString() == TypeNames.System_Runtime_InteropServices_ComImportAttribute); SignatureContext targetSignatureContext = SignatureContext.Create( method, - CreateComImportMarshallingInfoParser(env, parserDiagnostics, method, comImportAttribute), + CreateComImportMarshallingInfoParser(env, diagnostics, method, comImportAttribute), env, typeof(ConvertComImportToGeneratedComInterfaceAnalyzer).Assembly); @@ -148,7 +148,7 @@ public override void Initialize(AnalysisContext context) }); } - private static MarshallingInfoParser CreateComImportMarshallingInfoParser(StubEnvironment env, MarshallingInfoParserDiagnosticsBag diagnostics, IMethodSymbol method, AttributeData unparsedAttributeData) + private static MarshallingInfoParser CreateComImportMarshallingInfoParser(StubEnvironment env, GeneratorDiagnosticsBag diagnostics, IMethodSymbol method, AttributeData unparsedAttributeData) { var defaultInfo = new DefaultMarshallingInfo(CharEncoding.Utf16, null); diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs index 2de38bf8ac080f..a09f48109ee2f3 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs @@ -235,25 +235,24 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M } } - var generatorDiagnostics = new GeneratorDiagnosticBag(); - var diagnosticDescriptors = new DiagnosticDescriptorProvider(); + var locations = new MethodSignatureDiagnosticLocations(syntax); + var generatorDiagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), locations, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); if (lcidConversionAttr is not null) { // Using LCIDConversion with source-generated interop is not supported - generatorDiagnostics.ReportConfigurationNotSupported(diagnosticDescriptors, lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); + generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } GeneratedComInterfaceCompilationData.TryGetGeneratedComInterfaceAttributeFromInterface(symbol.ContainingType, out var generatedComAttribute); var generatedComInterfaceAttributeData = GeneratedComInterfaceCompilationData.GetDataFromAttribute(generatedComAttribute); // Create the stub. - var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(new DiagnosticDescriptorProvider(), generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); var signatureContext = SignatureContext.Create( symbol, DefaultMarshallingInfoParser.Create( environment, - marshallingInfoParserDiagnosticBag, + generatorDiagnostics, symbol, generatedComInterfaceAttributeData, generatedComAttribute), @@ -321,7 +320,7 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M signatureContext, containingSyntaxContext, methodSyntaxTemplate, - new MethodSignatureDiagnosticLocations(syntax), + locations, callConv.ToSequenceEqualImmutableArray(SyntaxEquivalentComparer.Instance), virtualMethodIndexData, new ComExceptionMarshalling(), diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs index 478032194215d8..9864fbed576ec5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs @@ -12,9 +12,11 @@ internal sealed class DiagnosticDescriptorProvider : IDiagnosticDescriptorProvid { public DiagnosticDescriptor InvalidMarshallingAttributeInfo => GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported; - public DiagnosticDescriptor GetConfigurationNotSupportedDescriptor(bool withValue) => withValue ? GeneratorDiagnostics.ConfigurationValueNotSupported : GeneratorDiagnostics.ConfigurationNotSupported; + public DiagnosticDescriptor ConfigurationNotSupported => GeneratorDiagnostics.ConfigurationNotSupported; - public DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic) + public DiagnosticDescriptor ConfigurationValueNotSupported => GeneratorDiagnostics.ConfigurationValueNotSupported; + + public DiagnosticDescriptor? GetDescriptor(GeneratorDiagnostic diagnostic) { return diagnostic switch { @@ -22,6 +24,7 @@ public DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic) GeneratorDiagnostic.NotSupported { NotSupportedDetails: null, TypePositionInfo: { IsManagedReturnPosition: false, MarshallingAttributeInfo: MarshalAsInfo } } => GeneratorDiagnostics.MarshalAsParameterConfigurationNotSupported, GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, + { IsFatal: false } => null, { TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupported, { TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupported, }; diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs index 21052824695d35..fb7c9452f6d4d5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs @@ -411,7 +411,7 @@ public class Ids /// Name of the method /// Specific reason the configuration is invalid public static void ReportInvalidStringMarshallingConfiguration( - this GeneratorDiagnosticBag diagnostics, + this GeneratorDiagnosticsBag diagnostics, AttributeData attributeData, string methodName, string detailsMessage) @@ -429,7 +429,7 @@ public static void ReportInvalidStringMarshallingConfiguration( /// Name of the method /// Specific reason the configuration is invalid public static void ReportInvalidExceptionMarshallingConfiguration( - this GeneratorDiagnosticBag diagnostics, + this GeneratorDiagnosticsBag diagnostics, AttributeData attributeData, string methodName, string detailsMessage) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs index c0fe6e63540025..23bf240f72370d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs @@ -47,7 +47,7 @@ public ManagedToNativeVTableMethodGenerator( ImmutableArray argTypes, bool setLastError, bool implicitThis, - Action marshallingNotSupportedCallback, + Action marshallingNotSupportedCallback, IMarshallingGeneratorFactory generatorFactory) { _setLastError = setLastError; @@ -78,7 +78,7 @@ public ManagedToNativeVTableMethodGenerator( foreach (var failure in bindingFailures) { - marshallingNotSupportedCallback(failure.Info, failure.Exception); + marshallingNotSupportedCallback(failure); } if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, _context)) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs index a3b9a07e12e992..414b57593ac39b 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs @@ -18,8 +18,7 @@ internal static class VirtualMethodPointerStubGenerator public static (MethodDeclarationSyntax, ImmutableArray) GenerateManagedToNativeStub( IncrementalMethodStubGenerationContext methodStub) { - var diagnosticDescriptors = new DiagnosticDescriptorProvider(); - var diagnostics = new GeneratorDiagnosticBag(); + var diagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), methodStub.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); // Generate stub code var stubGenerator = new ManagedToNativeVTableMethodGenerator( @@ -28,10 +27,7 @@ public static (MethodDeclarationSyntax, ImmutableArray) Generate methodStub.SignatureContext.ElementTypeInformation, methodStub.VtableIndexData.SetLastError, methodStub.VtableIndexData.ImplicitThisParameter, - ex => - { - diagnostics.ReportGeneratorDiagnostic(diagnosticDescriptors, methodStub.DiagnosticLocation, ex); - }, + diagnostics.ReportGeneratorDiagnostic, methodStub.ManagedToUnmanagedGeneratorFactory.GeneratorFactory); BlockSyntax code = stubGenerator.GenerateStubBody( @@ -69,8 +65,8 @@ private static MethodDeclarationSyntax PrintGeneratedSource( public static (MethodDeclarationSyntax, ImmutableArray) GenerateNativeToManagedStub( IncrementalMethodStubGenerationContext methodStub) { - var diagnosticDescriptors = new DiagnosticDescriptorProvider(); - var diagnostics = new GeneratorDiagnosticBag(); + var diagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), methodStub.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); + ImmutableArray elements = AddImplicitElementInfos(methodStub); // Generate stub code @@ -78,10 +74,7 @@ public static (MethodDeclarationSyntax, ImmutableArray) Generate methodStub.UnmanagedToManagedGeneratorFactory.Key.TargetFramework, methodStub.UnmanagedToManagedGeneratorFactory.Key.TargetFrameworkVersion, elements, - ex => - { - diagnostics.ReportGeneratorDiagnostic(diagnosticDescriptors, methodStub.DiagnosticLocation, ex); - }, + diagnostics.ReportGeneratorDiagnostic, methodStub.UnmanagedToManagedGeneratorFactory.GeneratorFactory); BlockSyntax code = stubGenerator.GenerateStubBody( diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs index 00aa31ed514303..dea2acac834342 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs @@ -230,8 +230,8 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M Debug.Assert(virtualMethodIndexAttr is not null); - var generatorDiagnostics = new GeneratorDiagnosticBag(); - var descriptorProvider = new DiagnosticDescriptorProvider(); + var locations = new MethodSignatureDiagnosticLocations(syntax); + var generatorDiagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), locations, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); // Process the LibraryImport attribute VirtualMethodIndexCompilationData? virtualMethodIndexData = ProcessVirtualMethodIndexAttribute(virtualMethodIndexAttr!); @@ -270,12 +270,11 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M if (lcidConversionAttr is not null) { // Using LCIDConversion with source-generated interop is not supported - generatorDiagnostics.ReportConfigurationNotSupported(descriptorProvider, lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); + generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } // Create the stub. - var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(descriptorProvider, generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); - var signatureContext = SignatureContext.Create(symbol, DefaultMarshallingInfoParser.Create(environment, marshallingInfoParserDiagnosticBag, symbol, virtualMethodIndexData, virtualMethodIndexAttr), environment, typeof(VtableIndexStubGenerator).Assembly); + var signatureContext = SignatureContext.Create(symbol, DefaultMarshallingInfoParser.Create(environment, generatorDiagnostics, symbol, virtualMethodIndexData, virtualMethodIndexAttr), environment, typeof(VtableIndexStubGenerator).Assembly); var containingSyntaxContext = new ContainingSyntaxContext(syntax); @@ -306,7 +305,7 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M signatureContext, containingSyntaxContext, methodSyntaxTemplate, - new MethodSignatureDiagnosticLocations(syntax), + locations, new SequenceEqualImmutableArray(callConv, SyntaxEquivalentComparer.Instance), VirtualMethodIndexData.From(virtualMethodIndexData), exceptionMarshallingInfo, @@ -318,7 +317,7 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M new ObjectUnwrapperInfo(unwrapperSyntax)); } - private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virtualMethodIndexAttr, ISymbol symbol, Compilation compilation, GeneratorDiagnosticBag diagnostics, VirtualMethodIndexCompilationData virtualMethodIndexData) + private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virtualMethodIndexAttr, ISymbol symbol, Compilation compilation, GeneratorDiagnosticsBag diagnostics, VirtualMethodIndexCompilationData virtualMethodIndexData) { if (virtualMethodIndexData.ExceptionMarshallingDefined) { @@ -344,7 +343,6 @@ private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virt } if (virtualMethodIndexData.ExceptionMarshalling == ExceptionMarshalling.Custom) { - var marshallingInfoParserDiagnosticBag = new MarshallingInfoParserDiagnosticsBag(new DiagnosticDescriptorProvider(), diagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); return virtualMethodIndexData.ExceptionMarshallingCustomType is null ? NoMarshallingInfo.Instance : CustomMarshallingInfoHelper.CreateNativeMarshallingInfoForNonSignatureElement( @@ -352,7 +350,7 @@ private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virt virtualMethodIndexData.ExceptionMarshallingCustomType!, virtualMethodIndexAttr, compilation, - marshallingInfoParserDiagnosticBag); + diagnostics); } // This should not be reached in normal usage, but a developer can cast any int to the ExceptionMarshalling enum, so we should handle this case without crashing the generator. diagnostics.ReportInvalidExceptionMarshallingConfiguration( diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/DefaultMarshallingInfoParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Common/DefaultMarshallingInfoParser.cs index 62b22f3ee112c7..d69a8d3b860a72 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Common/DefaultMarshallingInfoParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Common/DefaultMarshallingInfoParser.cs @@ -8,7 +8,7 @@ namespace Microsoft.Interop { internal static class DefaultMarshallingInfoParser { - public static MarshallingInfoParser Create(StubEnvironment env, MarshallingInfoParserDiagnosticsBag diagnostics, IMethodSymbol method, InteropAttributeCompilationData interopAttributeData, AttributeData unparsedAttributeData) + public static MarshallingInfoParser Create(StubEnvironment env, GeneratorDiagnosticsBag diagnostics, IMethodSymbol method, InteropAttributeCompilationData interopAttributeData, AttributeData unparsedAttributeData) { // Compute the current default string encoding value. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs index 4c94220dd2beb4..3891817bf1852f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.DotnetRuntime.Extensions; using static Microsoft.Interop.Analyzers.AnalyzerDiagnostics; @@ -93,10 +94,9 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context, INamedTypeSymbo // Use the DllImport attribute data and the method signature to do some of the work the generator will do after conversion. // If any diagnostics or failures to marshal are reported, then mark this diagnostic with a property signifying that it may require // later user work. - GeneratorDiagnosticBag diagnostics = new(); - MarshallingInfoParserDiagnosticsBag parserDiagnostics = new(new DiagnosticDescriptorProvider(), diagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR)); + GeneratorDiagnosticsBag diagnostics = new(new DiagnosticDescriptorProvider(), new MethodSignatureDiagnosticLocations((MethodDeclarationSyntax)method.DeclaringSyntaxReferences[0].GetSyntax()), SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR)); AttributeData dllImportAttribute = method.GetAttributes().First(attr => attr.AttributeClass.ToDisplayString() == TypeNames.DllImportAttribute); - SignatureContext targetSignatureContext = SignatureContext.Create(method, DefaultMarshallingInfoParser.Create(env, parserDiagnostics, method, CreateInteropAttributeDataFromDllImport(dllImportData), dllImportAttribute), env, typeof(ConvertToLibraryImportAnalyzer).Assembly); + SignatureContext targetSignatureContext = SignatureContext.Create(method, DefaultMarshallingInfoParser.Create(env, diagnostics, method, CreateInteropAttributeDataFromDllImport(dllImportData), dllImportAttribute), env, typeof(ConvertToLibraryImportAnalyzer).Assembly); var generatorFactoryKey = LibraryImportGeneratorHelpers.CreateGeneratorFactory(env, new LibraryImportGeneratorOptions(context.Options.AnalyzerConfigOptionsProvider.GlobalOptions)); diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs index df03fe7aeba34e..bca67a7fdefc97 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs @@ -10,9 +10,11 @@ internal sealed class DiagnosticDescriptorProvider : IDiagnosticDescriptorProvid { public DiagnosticDescriptor InvalidMarshallingAttributeInfo => GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported; - public DiagnosticDescriptor GetConfigurationNotSupportedDescriptor(bool withValue) => withValue ? GeneratorDiagnostics.ConfigurationValueNotSupported : GeneratorDiagnostics.ConfigurationNotSupported; + public DiagnosticDescriptor ConfigurationNotSupported => GeneratorDiagnostics.ConfigurationNotSupported; - public DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic) + public DiagnosticDescriptor ConfigurationValueNotSupported => GeneratorDiagnostics.ConfigurationValueNotSupported; + + public DiagnosticDescriptor? GetDescriptor(GeneratorDiagnostic diagnostic) { return diagnostic switch { @@ -20,6 +22,7 @@ public DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic) GeneratorDiagnostic.NotSupported { NotSupportedDetails: null, TypePositionInfo: { IsManagedReturnPosition: false, MarshallingAttributeInfo: MarshalAsInfo } } => GeneratorDiagnostics.MarshalAsParameterConfigurationNotSupported, GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, + { IsFatal: false } => null, { TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupported, { TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupported, }; diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs index ad59c12d1b9de6..953f02c338ce54 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs @@ -195,7 +195,7 @@ public class Ids /// Name of the method /// Specific reason the configuration is invalid public static void ReportInvalidStringMarshallingConfiguration( - this GeneratorDiagnosticBag diagnostics, + this GeneratorDiagnosticsBag diagnostics, AttributeData attributeData, string methodName, string detailsMessage) @@ -213,7 +213,7 @@ public static void ReportInvalidStringMarshallingConfiguration( /// Method with the configuration that cannot be forwarded /// Configuration name /// Configuration value - public static void ReportCannotForwardToDllImport(this GeneratorDiagnosticBag diagnostics, MethodSignatureDiagnosticLocations method, string name, string? value = null) + public static void ReportCannotForwardToDllImport(this GeneratorDiagnosticsBag diagnostics, MethodSignatureDiagnosticLocations method, string name, string? value = null) { diagnostics.ReportDiagnostic( DiagnosticInfo.Create( diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs index 26d9e014e674cf..e0912481fe23fc 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs @@ -252,8 +252,8 @@ private static IncrementalStubGenerationContext CalculateStubInformation( Debug.Assert(generatedDllImportAttr is not null); - var generatorDiagnostics = new GeneratorDiagnosticBag(); - DiagnosticDescriptorProvider descriptorProvider = new(); + var locations = new MethodSignatureDiagnosticLocations(originalSyntax); + var generatorDiagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), locations, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR)); // Process the LibraryImport attribute LibraryImportCompilationData libraryImportData = @@ -280,12 +280,11 @@ private static IncrementalStubGenerationContext CalculateStubInformation( if (lcidConversionAttr is not null) { // Using LCIDConversion with LibraryImport is not supported - generatorDiagnostics.ReportConfigurationNotSupported(descriptorProvider, lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); + generatorDiagnostics.ReportConfigurationNotSupported(lcidConversionAttr, nameof(TypeNames.LCIDConversionAttribute)); } // Create the stub. - var marshallingInfoParserDiagnosticsBag = new MarshallingInfoParserDiagnosticsBag(descriptorProvider, generatorDiagnostics, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR)); - var signatureContext = SignatureContext.Create(symbol, DefaultMarshallingInfoParser.Create(environment, marshallingInfoParserDiagnosticsBag, symbol, libraryImportData, generatedDllImportAttr), environment, typeof(LibraryImportGenerator).Assembly); + var signatureContext = SignatureContext.Create(symbol, DefaultMarshallingInfoParser.Create(environment, generatorDiagnostics, symbol, libraryImportData, generatedDllImportAttr), environment, typeof(LibraryImportGenerator).Assembly); var containingTypeContext = new ContainingSyntaxContext(originalSyntax); @@ -296,7 +295,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation( signatureContext, containingTypeContext, methodSyntaxTemplate, - new MethodSignatureDiagnosticLocations(originalSyntax), + locations, new SequenceEqualImmutableArray(additionalAttributes.ToImmutableArray(), SyntaxEquivalentComparer.Instance), LibraryImportData.From(libraryImportData), LibraryImportGeneratorHelpers.CreateGeneratorFactory(environment, options), @@ -308,8 +307,7 @@ private static (MemberDeclarationSyntax, ImmutableArray) Generat IncrementalStubGenerationContext pinvokeStub, LibraryImportGeneratorOptions options) { - DiagnosticDescriptorProvider descriptorProvider = new(); - var diagnostics = new GeneratorDiagnosticBag(); + var diagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), pinvokeStub.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR)); if (options.GenerateForwarders) { return (PrintForwarderStub(pinvokeStub.StubMethodSyntaxTemplate, explicitForwarding: true, pinvokeStub, diagnostics), pinvokeStub.Diagnostics.Array.AddRange(diagnostics.Diagnostics)); @@ -321,7 +319,7 @@ private static (MemberDeclarationSyntax, ImmutableArray) Generat pinvokeStub.GeneratorFactoryKey.Key.Version, pinvokeStub.SignatureContext.ElementTypeInformation, pinvokeStub.LibraryImportData.SetLastError && !options.GenerateForwarders, - ex => diagnostics.ReportGeneratorDiagnostic(descriptorProvider, pinvokeStub.DiagnosticLocation, ex), + diagnostics.ReportGeneratorDiagnostic, pinvokeStub.GeneratorFactoryKey.GeneratorFactory); // Check if the generator should produce a forwarder stub - regular DllImport. @@ -356,7 +354,7 @@ private static (MemberDeclarationSyntax, ImmutableArray) Generat return (pinvokeStub.ContainingSyntaxContext.WrapMemberInContainingSyntaxWithUnsafeModifier(PrintGeneratedSource(pinvokeStub.StubMethodSyntaxTemplate, pinvokeStub.SignatureContext, code)), pinvokeStub.Diagnostics.Array.AddRange(diagnostics.Diagnostics)); } - private static MemberDeclarationSyntax PrintForwarderStub(ContainingSyntax userDeclaredMethod, bool explicitForwarding, IncrementalStubGenerationContext stub, GeneratorDiagnosticBag diagnostics) + private static MemberDeclarationSyntax PrintForwarderStub(ContainingSyntax userDeclaredMethod, bool explicitForwarding, IncrementalStubGenerationContext stub, GeneratorDiagnosticsBag diagnostics) { LibraryImportData pinvokeData = stub.LibraryImportData with { EntryPoint = stub.LibraryImportData.EntryPoint ?? userDeclaredMethod.Identifier.ValueText }; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/CustomMarshallingInfoHelper.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/CustomMarshallingInfoHelper.cs index d3e456d37aacb4..e3dcb7a67ae4a7 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/CustomMarshallingInfoHelper.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/CustomMarshallingInfoHelper.cs @@ -17,7 +17,7 @@ internal static MarshallingInfo CreateNativeMarshallingInfo( GetMarshallingInfoCallback getMarshallingInfoCallback, int indirectionDepth, CountInfo parsedCountInfo, - MarshallingInfoParserDiagnosticsBag diagnostics, + GeneratorDiagnosticsBag diagnostics, Compilation compilation) { if (!ManualTypeMarshallingHelper.HasEntryPointMarshallerAttribute(entryPointType)) @@ -134,7 +134,7 @@ public static MarshallingInfo CreateNativeMarshallingInfoForNonSignatureElement( INamedTypeSymbol entryPointType, AttributeData attrData, Compilation compilation, - MarshallingInfoParserDiagnosticsBag diagnostics) + GeneratorDiagnosticsBag diagnostics) { if (!ManualTypeMarshallingHelper.HasEntryPointMarshallerAttribute(entryPointType)) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParserDiagnosticsBag.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/DiagnosticExtensions.cs similarity index 64% rename from src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParserDiagnosticsBag.cs rename to src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/DiagnosticExtensions.cs index 35f5dda81427d7..0922f858fb6a9d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParserDiagnosticsBag.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/DiagnosticExtensions.cs @@ -1,10 +1,8 @@ // 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.Collections.Generic; using System.Collections.Immutable; -using System.Resources; using Microsoft.CodeAnalysis; namespace Microsoft.Interop @@ -219,92 +217,4 @@ public static DiagnosticInfo CreateDiagnosticInfo( messageArgs: args); } } - - - public class MarshallingInfoParserDiagnosticsBag - { - private readonly IDiagnosticDescriptorProvider _descriptorProvider; - private readonly GeneratorDiagnosticBag _diagnostics; - private readonly ResourceManager _resourceManager; - private readonly Type _resourceSource; - - public MarshallingInfoParserDiagnosticsBag(IDiagnosticDescriptorProvider descriptorProvider, GeneratorDiagnosticBag diagnostics, ResourceManager resourceManager, Type resourceSource) - { - _descriptorProvider = descriptorProvider; - _diagnostics = diagnostics; - _resourceManager = resourceManager; - _resourceSource = resourceSource; - } - - /// - /// Report diagnostic for configuration that is not supported by the DLL import source generator - /// - /// Attribute specifying the unsupported configuration - /// Name of the configuration - /// [Optiona] Unsupported configuration value - public void ReportConfigurationNotSupported( - AttributeData attributeData, - string configurationName, - string? unsupportedValue) - { - _diagnostics.ReportConfigurationNotSupported(_descriptorProvider, attributeData, configurationName, unsupportedValue); - } - - public void ReportInvalidMarshallingAttributeInfo( - AttributeData attributeData, - string reasonResourceName, - params string[] reasonArgs) - { - _diagnostics.ReportInvalidMarshallingAttributeInfo(_descriptorProvider, attributeData, _resourceManager, _resourceSource, reasonResourceName, reasonArgs); - } - } - - public class GeneratorDiagnosticBag - { - private readonly List _diagnostics = new List(); - public IEnumerable Diagnostics => _diagnostics; - - public void ReportDiagnostic(DiagnosticInfo diagnostic) - { - _diagnostics.Add(diagnostic); - } - - public void ReportConfigurationNotSupported(IDiagnosticDescriptorProvider descriptorProvider, AttributeData attributeData, string configurationName, string? unsupportedValue) - { - if (unsupportedValue is null) - { - ReportDiagnostic(attributeData.CreateDiagnosticInfo(descriptorProvider.GetConfigurationNotSupportedDescriptor(withValue: false), configurationName)); - } - else - { - ReportDiagnostic(attributeData.CreateDiagnosticInfo(descriptorProvider.GetConfigurationNotSupportedDescriptor(withValue: true), unsupportedValue, configurationName)); - } - } - - public void ReportInvalidMarshallingAttributeInfo(IDiagnosticDescriptorProvider descriptorProvider, AttributeData attributeData, ResourceManager resourceManager, Type resourceSource, string reasonResourceName, params string[] reasonArgs) - { - ReportDiagnostic(attributeData.CreateDiagnosticInfo(descriptorProvider.InvalidMarshallingAttributeInfo, new LocalizableResourceString(reasonResourceName, resourceManager, resourceSource, reasonArgs))); - } - - public void ReportGeneratorDiagnostic(IDiagnosticDescriptorProvider descriptorProvider, ISignatureDiagnosticLocations locations, GeneratorDiagnostic diagnostic) - { - _diagnostics.Add(locations.CreateDiagnosticInfo(descriptorProvider, diagnostic)); - } - - public void ReportConfigurationNotSupported(IDiagnosticDescriptorProvider descriptorProvider, AttributeData attributeData, string configurationName) - { - ReportDiagnostic(attributeData.CreateDiagnosticInfo(descriptorProvider.GetConfigurationNotSupportedDescriptor(withValue: false), configurationName)); - } - } - - public static class IGeneratorDiagnosticsExtensions - { - public static void ReportConfigurationNotSupported(this MarshallingInfoParserDiagnosticsBag diagnostics, AttributeData attributeData, string configurationName) - => diagnostics.ReportConfigurationNotSupported(attributeData, configurationName, null); - } - - public class GeneratorDiagnosticProperties - { - public const string AddDisableRuntimeMarshallingAttribute = nameof(AddDisableRuntimeMarshallingAttribute); - } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratorDiagnosticsBag.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratorDiagnosticsBag.cs new file mode 100644 index 00000000000000..fcef859ae2aa50 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratorDiagnosticsBag.cs @@ -0,0 +1,118 @@ +// 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.Collections.Generic; +using System.Resources; +using Microsoft.CodeAnalysis; + +namespace Microsoft.Interop +{ + /// + /// A bag of diagnostics that generators can report diagnostics to. + /// + public class GeneratorDiagnosticsBag + { + private readonly IDiagnosticDescriptorProvider _descriptorProvider; + private readonly ISignatureDiagnosticLocations _locations; + private readonly ResourceManager _resourceManager; + private readonly Type _resourceSource; + + private readonly List _diagnostics = new(); + public IEnumerable Diagnostics => _diagnostics; + + /// + /// Construct a generator diagnostics bag. + /// + /// A provider of specific diagnostic descriptors to use. + /// A provider of locations for diagnostics on s. + /// A resource manager to resolve resource string parameters to diagnostics. + /// The type that represents the resource source. + public GeneratorDiagnosticsBag(IDiagnosticDescriptorProvider descriptorProvider, ISignatureDiagnosticLocations locations, ResourceManager resourceManager, Type resourceSource) + { + _descriptorProvider = descriptorProvider; + _locations = locations; + _resourceManager = resourceManager; + _resourceSource = resourceSource; + } + + /// + /// Report a diagnostic. + /// + /// The diagnostic info. + public void ReportDiagnostic(DiagnosticInfo diagnostic) + { + _diagnostics.Add(diagnostic); + } + + /// + /// Report diagnostic for configuration that is not supported by the DLL import source generator + /// + /// Attribute specifying the unsupported configuration + /// Name of the configuration + /// Unsupported configuration value + public void ReportConfigurationNotSupported( + AttributeData attributeData, + string configurationName, + string unsupportedValue) + { + ReportDiagnostic(attributeData.CreateDiagnosticInfo(_descriptorProvider.ConfigurationValueNotSupported, unsupportedValue, configurationName)); + } + + /// + /// Report diagnostic for configuration that is not supported by the DLL import source generator + /// + /// Attribute specifying the unsupported configuration + /// Name of the configuration + public void ReportConfigurationNotSupported( + AttributeData attributeData, + string configurationName) + { + ReportDiagnostic(attributeData.CreateDiagnosticInfo(_descriptorProvider.ConfigurationNotSupported, configurationName)); + } + + /// + /// Report a diagnostic for an invalid marshalling attribute. + /// + /// The attribute data. + /// A resource name with the string describing the reason the attribute is invalid. + /// The arguments for the localizable string. + public void ReportInvalidMarshallingAttributeInfo( + AttributeData attributeData, + string reasonResourceName, + params string[] reasonArgs) + { + ReportDiagnostic(attributeData.CreateDiagnosticInfo(_descriptorProvider.InvalidMarshallingAttributeInfo, new LocalizableResourceString(reasonResourceName, _resourceManager, _resourceSource, reasonArgs))); + } + + /// + /// Report a diagnostic generated when resolving a generator. + /// + /// The generated diagnostic. + /// The did not provide a diagnostic for a fatal diagnostic. + public void ReportGeneratorDiagnostic(GeneratorDiagnostic diagnostic) + { + DiagnosticDescriptor? descriptor = _descriptorProvider.GetDescriptor(diagnostic); + if (descriptor is null) + { + if (diagnostic.IsFatal) + { + throw new InvalidOperationException(); + } + return; + } + _diagnostics.Add(_locations.CreateDiagnosticInfo(descriptor, diagnostic)); + } + } + + /// + /// Properties that are common to many interop generators' diagnostics. These properties are used by code-fixers to provide a good user experience. + /// + public class GeneratorDiagnosticProperties + { + /// + /// The diagnostic can be resolved by adding the System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute to the assembly + /// + public const string AddDisableRuntimeMarshallingAttribute = nameof(AddDisableRuntimeMarshallingAttribute); + } +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalAsAttributeParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalAsAttributeParser.cs index d0433fcb9fb5b5..885ac8153759eb 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalAsAttributeParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalAsAttributeParser.cs @@ -27,10 +27,10 @@ public sealed record MarshalAsInfo( public sealed class MarshalAsAttributeParser : IMarshallingInfoAttributeParser, IUseSiteAttributeParser { private readonly Compilation _compilation; - private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; + private readonly GeneratorDiagnosticsBag _diagnostics; private readonly DefaultMarshallingInfo _defaultInfo; - public MarshalAsAttributeParser(Compilation compilation, MarshallingInfoParserDiagnosticsBag diagnostics, DefaultMarshallingInfo defaultInfo) + public MarshalAsAttributeParser(Compilation compilation, GeneratorDiagnosticsBag diagnostics, DefaultMarshallingInfo defaultInfo) { _compilation = compilation; _diagnostics = diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalUsingAttributeParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalUsingAttributeParser.cs index e65f92bbe136f8..cd791276254153 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalUsingAttributeParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshalUsingAttributeParser.cs @@ -15,9 +15,9 @@ namespace Microsoft.Interop public sealed class MarshalUsingAttributeParser : IMarshallingInfoAttributeParser, IUseSiteAttributeParser { private readonly Compilation _compilation; - private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; + private readonly GeneratorDiagnosticsBag _diagnostics; - public MarshalUsingAttributeParser(Compilation compilation, MarshallingInfoParserDiagnosticsBag diagnostics) + public MarshalUsingAttributeParser(Compilation compilation, GeneratorDiagnosticsBag diagnostics) { _compilation = compilation; _diagnostics = diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs index 4a896eda28ad16..23457d50f85b0a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingInfoParser.cs @@ -174,7 +174,7 @@ public static bool TryGetInfoForParamIndex(this IElementInfoProvider provider, A /// public sealed class MarshallingInfoParser { - private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; + private readonly GeneratorDiagnosticsBag _diagnostics; private readonly IElementInfoProvider _elementInfoProvider; private readonly ImmutableArray _useSiteMarshallingAttributeParsers; private readonly ImmutableArray _marshallingAttributeParsers; @@ -189,7 +189,7 @@ public sealed class MarshallingInfoParser /// Parsers for retrieving marshalling information from attributes and the managed type. /// Parsers for retrieving marshalling information from the managed type only. public MarshallingInfoParser( - MarshallingInfoParserDiagnosticsBag diagnostics, + GeneratorDiagnosticsBag diagnostics, IElementInfoProvider elementInfoProvider, ImmutableArray useSiteMarshallingAttributeParsers, ImmutableArray marshallingAttributeParsers, @@ -286,9 +286,9 @@ internal sealed class CycleDetectingElementInfoProvider : IElementInfoProvider { private ImmutableHashSet _activeInspectingElements = ImmutableHashSet.Empty; private readonly IElementInfoProvider _innerProvider; - private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; + private readonly GeneratorDiagnosticsBag _diagnostics; - public CycleDetectingElementInfoProvider(IElementInfoProvider innerProvider, MarshallingInfoParserDiagnosticsBag diagnostics) + public CycleDetectingElementInfoProvider(IElementInfoProvider innerProvider, GeneratorDiagnosticsBag diagnostics) { _innerProvider = innerProvider; _diagnostics = diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureDiagnosticLocations.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureDiagnosticLocations.cs index d530b04cfb043f..2705493f9155aa 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureDiagnosticLocations.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureDiagnosticLocations.cs @@ -9,16 +9,37 @@ namespace Microsoft.Interop { + /// + /// A provider for diagnostic descriptors for common error scenarios and for generator resolution. + /// public interface IDiagnosticDescriptorProvider { + /// + /// The diagnostic descriptor to use when the provided marshalling attribute is invalid. + /// DiagnosticDescriptor InvalidMarshallingAttributeInfo { get; } - DiagnosticDescriptor GetConfigurationNotSupportedDescriptor(bool withValue); - DiagnosticDescriptor GetDescriptor(GeneratorDiagnostic diagnostic); + /// + /// The diagnostic descriptor to use when the provided configuration is not supported. + /// + DiagnosticDescriptor ConfigurationNotSupported { get; } + /// + /// The diagnostic descriptor to use when the provided value for a given configuration isn't supported. + /// + DiagnosticDescriptor ConfigurationValueNotSupported { get; } + /// + /// Gets the diagnostic to use for the given generator diagnostic, or null if no diagnostic should be reported to the user. + /// + /// The diagnostic generated by the generator factory. + /// The descriptor to use to create the diagnostic, if any + /// + /// A descriptor must be returned if the diagnostic is fatal. + /// + DiagnosticDescriptor? GetDescriptor(GeneratorDiagnostic diagnostic); } public interface ISignatureDiagnosticLocations { - DiagnosticInfo CreateDiagnosticInfo(IDiagnosticDescriptorProvider descriptorProvider, GeneratorDiagnostic diagnostic); + DiagnosticInfo CreateDiagnosticInfo(DiagnosticDescriptor descriptor, GeneratorDiagnostic diagnostic); } public sealed record MethodSignatureDiagnosticLocations(string MethodIdentifier, ImmutableArray ManagedParameterLocations, Location FallbackLocation) : ISignatureDiagnosticLocations @@ -37,9 +58,8 @@ public bool Equals(MethodSignatureDiagnosticLocations other) public override int GetHashCode() => throw new UnreachableException(); - public DiagnosticInfo CreateDiagnosticInfo(IDiagnosticDescriptorProvider descriptorProvider, GeneratorDiagnostic diagnostic) + public DiagnosticInfo CreateDiagnosticInfo(DiagnosticDescriptor descriptor, GeneratorDiagnostic diagnostic) { - DiagnosticDescriptor descriptor = descriptorProvider.GetDescriptor(diagnostic); var (location, elementName) = diagnostic.TypePositionInfo switch { { ManagedIndex: >= 0 and int index, InstanceIdentifier: string identifier } => (ManagedParameterLocations[index], identifier), diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureElementInfoProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureElementInfoProvider.cs index cebdfe8404b9ad..a7446788b80000 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureElementInfoProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MethodSignatureElementInfoProvider.cs @@ -12,11 +12,11 @@ namespace Microsoft.Interop public sealed class MethodSignatureElementInfoProvider : IElementInfoProvider { private readonly Compilation _compilation; - private readonly MarshallingInfoParserDiagnosticsBag _generatorDiagnostics; + private readonly GeneratorDiagnosticsBag _generatorDiagnostics; private readonly IMethodSymbol _method; private readonly ImmutableArray _useSiteAttributeParsers; - public MethodSignatureElementInfoProvider(Compilation compilation, MarshallingInfoParserDiagnosticsBag generatorDiagnostics, IMethodSymbol method, ImmutableArray useSiteAttributeParsers) + public MethodSignatureElementInfoProvider(Compilation compilation, GeneratorDiagnosticsBag generatorDiagnostics, IMethodSymbol method, ImmutableArray useSiteAttributeParsers) { _compilation = compilation; _generatorDiagnostics = generatorDiagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/NativeMarshallingAttributeParser.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/NativeMarshallingAttributeParser.cs index 0c17cf405fe715..88df42587e5392 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/NativeMarshallingAttributeParser.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/NativeMarshallingAttributeParser.cs @@ -9,9 +9,9 @@ namespace Microsoft.Interop public sealed class NativeMarshallingAttributeParser : IMarshallingInfoAttributeParser { private readonly Compilation _compilation; - private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; + private readonly GeneratorDiagnosticsBag _diagnostics; - public NativeMarshallingAttributeParser(Compilation compilation, MarshallingInfoParserDiagnosticsBag diagnostics) + public NativeMarshallingAttributeParser(Compilation compilation, GeneratorDiagnosticsBag diagnostics) { _compilation = compilation; _diagnostics = diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs index 15d867a477bc54..05a060019ab3f5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/StringMarshallingInfoProvider.cs @@ -15,11 +15,11 @@ namespace Microsoft.Interop public sealed class StringMarshallingInfoProvider : ITypeBasedMarshallingInfoProvider { private readonly Compilation _compilation; - private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; + private readonly GeneratorDiagnosticsBag _diagnostics; private readonly AttributeData _stringMarshallingCustomAttribute; private readonly DefaultMarshallingInfo _defaultMarshallingInfo; - public StringMarshallingInfoProvider(Compilation compilation, MarshallingInfoParserDiagnosticsBag diagnostics, AttributeData stringMarshallingCustomAttribute, DefaultMarshallingInfo defaultMarshallingInfo) + public StringMarshallingInfoProvider(Compilation compilation, GeneratorDiagnosticsBag diagnostics, AttributeData stringMarshallingCustomAttribute, DefaultMarshallingInfo defaultMarshallingInfo) { _compilation = compilation; _diagnostics = diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UseSiteAttributeProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UseSiteAttributeProvider.cs index ec4fb522d533fb..fb4700cc4308ba 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UseSiteAttributeProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/UseSiteAttributeProvider.cs @@ -15,7 +15,7 @@ public sealed class UseSiteAttributeProvider { private readonly ImmutableDictionary _useSiteAttributesByIndirectionDepth; private readonly int _maxIndirectionLevelDataProvided; - private readonly MarshallingInfoParserDiagnosticsBag _diagnostics; + private readonly GeneratorDiagnosticsBag _diagnostics; private int _maxIndirectionLevelUsed; /// @@ -30,7 +30,7 @@ internal UseSiteAttributeProvider( ImmutableArray useSiteAttributeParsers, IEnumerable useSiteAttributes, IElementInfoProvider elementInfoProvider, - MarshallingInfoParserDiagnosticsBag diagnostics, + GeneratorDiagnosticsBag diagnostics, GetMarshallingInfoCallback getMarshallingInfoCallback) { ImmutableDictionary.Builder useSiteAttributesByIndirectionDepth = ImmutableDictionary.CreateBuilder(); From 7cc72815f9e62820ecd31b138e27d024d0d1cf27 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 16 Jun 2023 10:12:40 -0700 Subject: [PATCH 4/8] Fix JS generators --- .../JSImportGenerator/JSExportGenerator.cs | 19 +++++++------- .../JSImportGenerator/JSImportGenerator.cs | 25 ++++++++----------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs index dccd4d36c44de4..5c814204977308 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs @@ -202,8 +202,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation( } // Create the stub. - var marshallingInfoParserDiagnosticBag = - var signatureContext = JSSignatureContext.Create(symbol, environment, marshallingInfoParserDiagnosticBag, ct); + var signatureContext = JSSignatureContext.Create(symbol, environment, generatorDiagnostics, ct); var containingTypeContext = new ContainingSyntaxContext(originalSyntax); @@ -291,17 +290,17 @@ private static NamespaceDeclarationSyntax GenerateRegSource( private static (MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray) GenerateSource( IncrementalStubGenerationContext incrementalContext) { - var diagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), incrementalContext.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); + var diagnostics = new GeneratorDiagnosticsBag(new DescriptorProvider(), incrementalContext.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); // Generate stub code var stubGenerator = new JSExportCodeGenerator( - incrementalContext.GeneratorFactoryKey.Key.TargetFramework, - incrementalContext.GeneratorFactoryKey.Key.TargetFrameworkVersion, - incrementalContext.SignatureContext.SignatureContext.ElementTypeInformation, - incrementalContext.JSExportData, - incrementalContext.SignatureContext, - diagnostics.ReportGeneratorDiagnostic, - incrementalContext.GeneratorFactoryKey.GeneratorFactory); + incrementalContext.GeneratorFactoryKey.Key.TargetFramework, + incrementalContext.GeneratorFactoryKey.Key.TargetFrameworkVersion, + incrementalContext.SignatureContext.SignatureContext.ElementTypeInformation, + incrementalContext.JSExportData, + incrementalContext.SignatureContext, + diagnostics.ReportGeneratorDiagnostic, + incrementalContext.GeneratorFactoryKey.GeneratorFactory); var wrapperName = "__Wrapper_" + incrementalContext.StubMethodSyntaxTemplate.Identifier + "_" + incrementalContext.SignatureContext.TypesHash; diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs index 4970cd7dddb724..e02b1688e3ab3d 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs @@ -178,7 +178,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation( Debug.Assert(jsImportAttr is not null); var locations = new MethodSignatureDiagnosticLocations(originalSyntax); - var diagnosticsBag = new GeneratorDiagnosticsBag(new DescriptorProvider(), locations, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); + var generatorDiagnostics = new GeneratorDiagnosticsBag(new DescriptorProvider(), locations, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); // Process the JSImport attribute JSImportData? jsImportData = ProcessJSImportAttribute(jsImportAttr!); @@ -190,7 +190,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation( } // Create the stub. - var signatureContext = JSSignatureContext.Create(symbol, environment, diagnosticsBag, ct); + var signatureContext = JSSignatureContext.Create(symbol, environment, generatorDiagnostics, ct); var containingTypeContext = new ContainingSyntaxContext(originalSyntax); @@ -199,7 +199,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation( signatureContext, containingTypeContext, methodSyntaxTemplate, - , + locations, jsImportData, CreateGeneratorFactory(environment, options), new SequenceEqualImmutableArray(generatorDiagnostics.Diagnostics.ToImmutableArray())); @@ -215,20 +215,17 @@ private static IncrementalStubGenerationContext CalculateStubInformation( private static (MemberDeclarationSyntax, ImmutableArray) GenerateSource( IncrementalStubGenerationContext incrementalContext) { - var diagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), incrementalContext.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); + var diagnostics = new GeneratorDiagnosticsBag(new DescriptorProvider(), incrementalContext.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR)); // Generate stub code var stubGenerator = new JSImportCodeGenerator( - incrementalContext.GeneratorFactoryKey.Key.TargetFramework, - incrementalContext.GeneratorFactoryKey.Key.TargetFrameworkVersion, - incrementalContext.SignatureContext.SignatureContext.ElementTypeInformation, - incrementalContext.JSImportData, - incrementalContext.SignatureContext, - ex => - { - diagnostics.ReportGeneratorDiagnostic(descriptorProvider, incrementalContext.DiagnosticLocation, ex); - }, - incrementalContext.GeneratorFactoryKey.GeneratorFactory); + incrementalContext.GeneratorFactoryKey.Key.TargetFramework, + incrementalContext.GeneratorFactoryKey.Key.TargetFrameworkVersion, + incrementalContext.SignatureContext.SignatureContext.ElementTypeInformation, + incrementalContext.JSImportData, + incrementalContext.SignatureContext, + diagnostics.ReportGeneratorDiagnostic, + incrementalContext.GeneratorFactoryKey.GeneratorFactory); BlockSyntax code = stubGenerator.GenerateJSImportBody(); From 77c4aa5db9e9b78fae22b6bedc05f521f9c1b91d Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 16 Jun 2023 10:52:10 -0700 Subject: [PATCH 5/8] Don't reference the live generators for the tasks project builds. Use the generators from the LKG SDK. --- eng/generators.targets | 2 ++ src/tasks/Directory.Build.props | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 src/tasks/Directory.Build.props diff --git a/eng/generators.targets b/eng/generators.targets index 64aa5d6c95c3e9..73cff0ca20cbc3 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -19,6 +19,7 @@ + + + true + + From 74a13881ece6c70b2be6a67054c1a0546f23cd48 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 16 Jun 2023 10:53:28 -0700 Subject: [PATCH 6/8] Remove APIs needed for compatibility now that we've fixed the compat issue. --- .../Marshalling/CharMarshallingGeneratorFactory.cs | 8 -------- .../NoMarshallingInfoErrorMarshallingFactory.cs | 6 ------ 2 files changed, 14 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshallingGeneratorFactory.cs index bb43170cce7900..d60e3b8a494711 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshallingGeneratorFactory.cs @@ -18,14 +18,6 @@ public sealed class CharMarshallingGeneratorFactory : IMarshallingGeneratorFacto private readonly bool _useBlittableMarshallerForUtf16; private readonly string _stringMarshallingAttribute; - // Needed for API compatibility with preview 4 - public CharMarshallingGeneratorFactory(IMarshallingGeneratorFactory inner, bool useBlittableMarshallerForUtf16) - { - _inner = inner; - _useBlittableMarshallerForUtf16 = useBlittableMarshallerForUtf16; - _stringMarshallingAttribute = "LibraryImportGenerator"; - } - public CharMarshallingGeneratorFactory(IMarshallingGeneratorFactory inner, bool useBlittableMarshallerForUtf16, string stringMarshallingAttribute) { _inner = inner; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/NoMarshallingInfoErrorMarshallingFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/NoMarshallingInfoErrorMarshallingFactory.cs index 5d71d56896f847..fd0ab1d1c706d2 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/NoMarshallingInfoErrorMarshallingFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/NoMarshallingInfoErrorMarshallingFactory.cs @@ -27,12 +27,6 @@ public ResolvedGenerator Create( return _inner.Create(info, context); } - // Necessary for API compatibility with preview 4 SDK - public NoMarshallingInfoErrorMarshallingFactory(IMarshallingGeneratorFactory inner) - : this(inner, DefaultTypeToErrorMessageMap("LibraryImportAttribute")) - { - } - public NoMarshallingInfoErrorMarshallingFactory(IMarshallingGeneratorFactory inner, string stringMarshallingAttribute) : this(inner, DefaultTypeToErrorMessageMap(stringMarshallingAttribute)) { From 93c3ad36399e7fae06415eb70d8c5d0c74068033 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 16 Jun 2023 15:43:49 -0700 Subject: [PATCH 7/8] Use the UseLocalTargetingRuntimePack property in the project reference condition, as this best describes what we actually want to check. --- eng/generators.targets | 6 ++---- src/tasks/Directory.Build.props | 7 ------- 2 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 src/tasks/Directory.Build.props diff --git a/eng/generators.targets b/eng/generators.targets index 73cff0ca20cbc3..be12811a614e32 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -19,11 +19,10 @@ - - - true - - From 966f4ab7bf84f2855e1d4ad21b2e1fef4aa9f405 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 22 Jun 2023 13:58:41 -0700 Subject: [PATCH 8/8] Remove dead code and pass the generator diagnostics bag directly. --- .../JSExportCodeGenerator.cs | 10 ++-- .../JSImportGenerator/JSExportGenerator.cs | 2 +- .../JSImportCodeGenerator.cs | 10 ++-- .../JSImportGenerator/JSImportGenerator.cs | 2 +- .../ManagedToNativeVTableMethodGenerator.cs | 7 +-- .../UnmanagedToManagedStubGenerator.cs | 7 +-- .../VirtualMethodPointerStubGenerator.cs | 9 ++-- .../LibraryImportGenerator.cs | 2 +- .../PInvokeStubCodeGenerator.cs | 7 +-- .../GeneratorDiagnosticsBag.cs | 14 ++++++ .../SymbolDiagnosticLocations.cs | 50 ------------------- 11 files changed, 36 insertions(+), 84 deletions(-) delete mode 100644 src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SymbolDiagnosticLocations.cs diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportCodeGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportCodeGenerator.cs index 016b4a829b64e2..9221bef508f3b9 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportCodeGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportCodeGenerator.cs @@ -25,7 +25,7 @@ public JSExportCodeGenerator( ImmutableArray argTypes, JSExportData attributeData, JSSignatureContext signatureContext, - Action marshallingNotSupportedCallback, + GeneratorDiagnosticsBag diagnosticsBag, IMarshallingGeneratorFactory generatorFactory) { _signatureContext = signatureContext; @@ -33,10 +33,8 @@ public JSExportCodeGenerator( _context = new JSExportCodeContext(attributeData, innerContext); _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new EmptyJSGenerator(), out var bindingFailures); - foreach (var failure in bindingFailures) - { - marshallingNotSupportedCallback(failure); - } + + diagnosticsBag.ReportGeneratorDiagnostics(bindingFailures); if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, null)) { @@ -51,7 +49,7 @@ public JSExportCodeGenerator( BoundGenerator spanArg = _marshallers.SignatureMarshallers.FirstOrDefault(m => m.TypeInfo.MarshallingAttributeInfo is JSMarshallingInfo(_, JSSpanTypeInfo)); if (spanArg != default) { - marshallingNotSupportedCallback(new GeneratorDiagnostic.NotSupported(spanArg.TypeInfo, _context) + diagnosticsBag.ReportGeneratorDiagnostic(new GeneratorDiagnostic.NotSupported(spanArg.TypeInfo, _context) { NotSupportedDetails = SR.SpanAndTaskNotSupported }); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs index 5c814204977308..cf647746fb29c8 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs @@ -299,7 +299,7 @@ private static (MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, I incrementalContext.SignatureContext.SignatureContext.ElementTypeInformation, incrementalContext.JSExportData, incrementalContext.SignatureContext, - diagnostics.ReportGeneratorDiagnostic, + diagnostics, incrementalContext.GeneratorFactoryKey.GeneratorFactory); var wrapperName = "__Wrapper_" + incrementalContext.StubMethodSyntaxTemplate.Identifier + "_" + incrementalContext.SignatureContext.TypesHash; diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportCodeGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportCodeGenerator.cs index 946077fae2c3be..2c1d49fd3dd12e 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportCodeGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportCodeGenerator.cs @@ -32,7 +32,7 @@ public JSImportCodeGenerator( ImmutableArray argTypes, JSImportData attributeData, JSSignatureContext signatureContext, - Action marshallingNotSupportedCallback, + GeneratorDiagnosticsBag diagnosticsBag, IMarshallingGeneratorFactory generatorFactory) { _signatureContext = signatureContext; @@ -40,10 +40,8 @@ public JSImportCodeGenerator( _context = new JSImportCodeContext(attributeData, innerContext); _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new EmptyJSGenerator(), out var bindingFailures); - foreach (var failure in bindingFailures) - { - marshallingNotSupportedCallback(failure); - } + diagnosticsBag.ReportGeneratorDiagnostics(bindingFailures); + if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, null)) { // If we need a different native return identifier, then recreate the context with the correct identifier before we generate any code. @@ -57,7 +55,7 @@ public JSImportCodeGenerator( BoundGenerator spanArg = _marshallers.SignatureMarshallers.FirstOrDefault(m => m.TypeInfo.MarshallingAttributeInfo is JSMarshallingInfo(_, JSSpanTypeInfo)); if (spanArg != default) { - marshallingNotSupportedCallback(new GeneratorDiagnostic.NotSupported(spanArg.TypeInfo, _context) + diagnosticsBag.ReportGeneratorDiagnostic(new GeneratorDiagnostic.NotSupported(spanArg.TypeInfo, _context) { NotSupportedDetails = SR.SpanAndTaskNotSupported }); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs index e02b1688e3ab3d..99bdb634b7f9b1 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportGenerator.cs @@ -224,7 +224,7 @@ private static (MemberDeclarationSyntax, ImmutableArray) Generat incrementalContext.SignatureContext.SignatureContext.ElementTypeInformation, incrementalContext.JSImportData, incrementalContext.SignatureContext, - diagnostics.ReportGeneratorDiagnostic, + diagnostics, incrementalContext.GeneratorFactoryKey.GeneratorFactory); BlockSyntax code = stubGenerator.GenerateJSImportBody(); diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs index 23bf240f72370d..4c45246c145509 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ManagedToNativeVTableMethodGenerator.cs @@ -47,7 +47,7 @@ public ManagedToNativeVTableMethodGenerator( ImmutableArray argTypes, bool setLastError, bool implicitThis, - Action marshallingNotSupportedCallback, + GeneratorDiagnosticsBag diagnosticsBag, IMarshallingGeneratorFactory generatorFactory) { _setLastError = setLastError; @@ -76,10 +76,7 @@ public ManagedToNativeVTableMethodGenerator( _context = new ManagedToNativeStubCodeContext(targetFramework, targetFrameworkVersion, ReturnIdentifier, ReturnIdentifier); _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new Forwarder(), out var bindingFailures); - foreach (var failure in bindingFailures) - { - marshallingNotSupportedCallback(failure); - } + diagnosticsBag.ReportGeneratorDiagnostics(bindingFailures); if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, _context)) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnmanagedToManagedStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnmanagedToManagedStubGenerator.cs index 9038d96f291812..6d255912aedaab 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnmanagedToManagedStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/UnmanagedToManagedStubGenerator.cs @@ -24,16 +24,13 @@ public UnmanagedToManagedStubGenerator( TargetFramework targetFramework, Version targetFrameworkVersion, ImmutableArray argTypes, - Action marshallingNotSupportedCallback, + GeneratorDiagnosticsBag diagnosticsBag, IMarshallingGeneratorFactory generatorFactory) { _context = new NativeToManagedStubCodeContext(targetFramework, targetFrameworkVersion, ReturnIdentifier, ReturnIdentifier); _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new Forwarder(), out var bindingDiagnostics); - foreach (var diagnostic in bindingDiagnostics) - { - marshallingNotSupportedCallback(diagnostic); - } + diagnosticsBag.ReportGeneratorDiagnostics(bindingDiagnostics); if (_marshallers.NativeReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.NativeReturnMarshaller.TypeInfo, _context)) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs index 414b57593ac39b..fe931a812bf341 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs @@ -27,7 +27,7 @@ public static (MethodDeclarationSyntax, ImmutableArray) Generate methodStub.SignatureContext.ElementTypeInformation, methodStub.VtableIndexData.SetLastError, methodStub.VtableIndexData.ImplicitThisParameter, - diagnostics.ReportGeneratorDiagnostic, + diagnostics, methodStub.ManagedToUnmanagedGeneratorFactory.GeneratorFactory); BlockSyntax code = stubGenerator.GenerateStubBody( @@ -74,7 +74,7 @@ public static (MethodDeclarationSyntax, ImmutableArray) Generate methodStub.UnmanagedToManagedGeneratorFactory.Key.TargetFramework, methodStub.UnmanagedToManagedGeneratorFactory.Key.TargetFrameworkVersion, elements, - diagnostics.ReportGeneratorDiagnostic, + diagnostics, methodStub.UnmanagedToManagedGeneratorFactory.GeneratorFactory); BlockSyntax code = stubGenerator.GenerateStubBody( @@ -169,12 +169,13 @@ public static BlockSyntax GenerateVirtualMethodTableSlotAssignments(IEnumerable< private static FunctionPointerTypeSyntax GenerateUnmanagedFunctionPointerTypeForMethod(IncrementalMethodStubGenerationContext method) { + var diagnostics = new GeneratorDiagnosticsBag(new DiagnosticDescriptorProvider(), method.DiagnosticLocation, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.ComInterfaceGenerator.SR)); + var stubGenerator = new UnmanagedToManagedStubGenerator( method.UnmanagedToManagedGeneratorFactory.Key.TargetFramework, method.UnmanagedToManagedGeneratorFactory.Key.TargetFrameworkVersion, AddImplicitElementInfos(method), - // Swallow diagnostics here since the diagnostics will be reported by the unmanaged->managed stub generation - diag => { }, + diagnostics, method.UnmanagedToManagedGeneratorFactory.GeneratorFactory); List functionPointerParameters = new(); diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs index e0912481fe23fc..2d61f237b27301 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs @@ -319,7 +319,7 @@ private static (MemberDeclarationSyntax, ImmutableArray) Generat pinvokeStub.GeneratorFactoryKey.Key.Version, pinvokeStub.SignatureContext.ElementTypeInformation, pinvokeStub.LibraryImportData.SetLastError && !options.GenerateForwarders, - diagnostics.ReportGeneratorDiagnostic, + diagnostics, pinvokeStub.GeneratorFactoryKey.GeneratorFactory); // Check if the generator should produce a forwarder stub - regular DllImport. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs index 6476e228f20417..34d09a70a66e6f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs @@ -50,7 +50,7 @@ public PInvokeStubCodeGenerator( Version targetFrameworkVersion, ImmutableArray argTypes, bool setLastError, - Action marshallingNotSupportedCallback, + GeneratorDiagnosticsBag diagnosticsBag, IMarshallingGeneratorFactory generatorFactory) { _setLastError = setLastError; @@ -70,10 +70,7 @@ public PInvokeStubCodeGenerator( _context = new ManagedToNativeStubCodeContext(targetFramework, targetFrameworkVersion, ReturnIdentifier, ReturnIdentifier); _marshallers = BoundGenerators.Create(argTypes, generatorFactory, _context, new Forwarder(), out var bindingDiagnostics); - foreach (var diagnostic in bindingDiagnostics) - { - marshallingNotSupportedCallback(diagnostic); - } + diagnosticsBag.ReportGeneratorDiagnostics(bindingDiagnostics); if (_marshallers.ManagedReturnMarshaller.Generator.UsesNativeIdentifier(_marshallers.ManagedReturnMarshaller.TypeInfo, _context)) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratorDiagnosticsBag.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratorDiagnosticsBag.cs index fcef859ae2aa50..2bc682244e259d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratorDiagnosticsBag.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/GeneratorDiagnosticsBag.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Resources; using Microsoft.CodeAnalysis; @@ -103,6 +104,19 @@ public void ReportGeneratorDiagnostic(GeneratorDiagnostic diagnostic) } _diagnostics.Add(_locations.CreateDiagnosticInfo(descriptor, diagnostic)); } + + /// + /// Report a diagnostic generated when resolving a generator. + /// + /// The generated diagnostic. + /// The did not provide a diagnostic for a fatal diagnostic. + public void ReportGeneratorDiagnostics(ImmutableArray diagnostics) + { + foreach (var diagnostic in diagnostics) + { + ReportGeneratorDiagnostic(diagnostic); + } + } } /// diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SymbolDiagnosticLocations.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SymbolDiagnosticLocations.cs deleted file mode 100644 index 02331348885a6d..00000000000000 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SymbolDiagnosticLocations.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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.Collections.Immutable; -using System.Linq; -using Microsoft.CodeAnalysis; - -namespace Microsoft.Interop -{ - public sealed class SymbolDiagnosticLocations - { - private SymbolDiagnosticLocations(string identifier, Location location) - { - Identifier = identifier; - IdentifierLocation = location; - } - - public string Identifier { get; init; } - - public Location IdentifierLocation { get; init; } - - public required ImmutableArray<(string FullyQualifiedName, Location Location)> AttributeLocations { get; init; } - - public bool Equals(SymbolDiagnosticLocations other) - { - return Identifier == other.Identifier - && AttributeLocations.SequenceEqual(other.AttributeLocations) - && IdentifierLocation.Equals(other.IdentifierLocation); - } - - public static SymbolDiagnosticLocations CreateForReturnType(IMethodSymbol symbol) - { - return new SymbolDiagnosticLocations(symbol.Name, symbol.Locations[0]) - { - AttributeLocations = symbol.GetReturnTypeAttributes().Select(a => (a.AttributeClass.ToDisplayString(), Location.Create(a.ApplicationSyntaxReference.SyntaxTree, a.ApplicationSyntaxReference.Span))).ToImmutableArray() - }; - } - - public static SymbolDiagnosticLocations Create(ISymbol symbol) - { - return new SymbolDiagnosticLocations(symbol.Name, symbol.Locations[0]) - { - AttributeLocations = symbol.GetAttributes().Select(a => (a.AttributeClass.ToDisplayString(), Location.Create(a.ApplicationSyntaxReference.SyntaxTree, a.ApplicationSyntaxReference.Span))).ToImmutableArray() - }; - } - - public override int GetHashCode() => throw new UnreachableException(); - } -}