Skip to content

Commit 49da0bd

Browse files
authored
Change the ComInterfaceGenerator to output source in one file per interface and use file-scoped types (#83055)
1 parent 4699358 commit 49da0bd

30 files changed

+1340
-529
lines changed

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

Lines changed: 447 additions & 79 deletions
Large diffs are not rendered by default.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Ids
2121
public const string TypeNotSupported = Prefix + "1051";
2222
public const string ConfigurationNotSupported = Prefix + "1052";
2323
public const string MethodNotDeclaredInAttributedInterface = Prefix + "1091";
24+
public const string InvalidGeneratedComInterfaceAttributeUsage = Prefix + "1092";
2425
}
2526

2627
private const string Category = "ComInterfaceGenerator";
@@ -175,11 +176,21 @@ public class Ids
175176
isEnabledByDefault: true,
176177
description: GetResourceString(nameof(SR.MethodNotDeclaredInAttributedInterfaceDescription)));
177178

179+
public static readonly DiagnosticDescriptor InvalidAttributedInterfaceMissingGuidAttribute =
180+
new DiagnosticDescriptor(
181+
Ids.InvalidGeneratedComInterfaceAttributeUsage,
182+
GetResourceString(nameof(SR.InvalidGeneratedComInterfaceAttributeUsageTitle)),
183+
GetResourceString(nameof(SR.InvalidGeneratedComInterfaceAttributeUsageMissingGuidAttribute)),
184+
Category,
185+
DiagnosticSeverity.Error,
186+
isEnabledByDefault: true,
187+
description: GetResourceString(nameof(SR.InvalidGeneratedComInterfaceAttributeUsageDescription)));
178188

179189
private readonly List<Diagnostic> _diagnostics = new List<Diagnostic>();
180190

181191
public IEnumerable<Diagnostic> Diagnostics => _diagnostics;
182192

193+
183194
/// <summary>
184195
/// Report diagnostic for invalid configuration for string marshalling.
185196
/// </summary>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
using Microsoft.CodeAnalysis;
55
using Microsoft.CodeAnalysis.CSharp.Syntax;
66
using System;
7+
using System.Collections.Immutable;
78

89
namespace Microsoft.Interop
910
{
11+
internal abstract record GeneratedMethodContextBase(ManagedTypeInfo OriginalDefiningType, SequenceEqualImmutableArray<Diagnostic> Diagnostics);
12+
1013
internal sealed record IncrementalMethodStubGenerationContext(
1114
SignatureContext SignatureContext,
1215
ContainingSyntaxContext ContainingSyntaxContext,
@@ -19,5 +22,5 @@ internal sealed record IncrementalMethodStubGenerationContext(
1922
MarshallingGeneratorFactoryKey<(TargetFramework TargetFramework, Version TargetFrameworkVersion)> UnmanagedToManagedGeneratorFactory,
2023
ManagedTypeInfo TypeKeyOwner,
2124
SequenceEqualImmutableArray<Diagnostic> Diagnostics,
22-
TypeSyntax UnwrapperSyntax);
25+
TypeSyntax UnwrapperSyntax) : GeneratedMethodContextBase(TypeKeyOwner, Diagnostics);
2326
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ internal static class IncrementalValuesProviderExtensions
3030
return builder.MoveToImmutable();
3131
});
3232
}
33+
34+
public static IncrementalValuesProvider<TNode> SelectNormalized<TNode>(this IncrementalValuesProvider<TNode> provider)
35+
where TNode : SyntaxNode
36+
{
37+
return provider.Select((node, ct) => node.NormalizeWhitespace());
38+
}
3339
}
3440
}

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx

Lines changed: 231 additions & 222 deletions
Large diffs are not rendered by default.

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@
9292
<target state="translated">Zadaná hodnota není známý příznak výčtu ExceptionMarsnuming.</target>
9393
<note />
9494
</trans-unit>
95+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageDescription">
96+
<source>Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</source>
97+
<target state="new">Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</target>
98+
<note />
99+
</trans-unit>
100+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageMissingGuidAttribute">
101+
<source>Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</source>
102+
<target state="new">Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</target>
103+
<note />
104+
</trans-unit>
105+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageTitle">
106+
<source>Invalid 'GeneratedComInterfaceAttribute' usage.</source>
107+
<target state="new">Invalid 'GeneratedComInterfaceAttribute' usage.</target>
108+
<note />
109+
</trans-unit>
95110
<trans-unit id="InvalidStringMarshallingConfigurationDescription">
96111
<source>The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' is invalid.</source>
97112
<target state="translated">Konfigurace StringMarshalling a StringMarshallingCustomType je neplatná.</target>

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@
9292
<target state="translated">Der angegebene Wert ist kein bekanntes Flag der „ExceptionMarshalling“-Enumeration.</target>
9393
<note />
9494
</trans-unit>
95+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageDescription">
96+
<source>Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</source>
97+
<target state="new">Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</target>
98+
<note />
99+
</trans-unit>
100+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageMissingGuidAttribute">
101+
<source>Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</source>
102+
<target state="new">Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</target>
103+
<note />
104+
</trans-unit>
105+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageTitle">
106+
<source>Invalid 'GeneratedComInterfaceAttribute' usage.</source>
107+
<target state="new">Invalid 'GeneratedComInterfaceAttribute' usage.</target>
108+
<note />
109+
</trans-unit>
95110
<trans-unit id="InvalidStringMarshallingConfigurationDescription">
96111
<source>The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' is invalid.</source>
97112
<target state="translated">Die Konfiguration von \"StringMarshalling\" und \"StringMarshallingCustomType\" ist ungültig.</target>

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@
9292
<target state="translated">El valor proporcionado no es una marca conocida de la enumeración “ExceptionMarshalling”.</target>
9393
<note />
9494
</trans-unit>
95+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageDescription">
96+
<source>Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</source>
97+
<target state="new">Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</target>
98+
<note />
99+
</trans-unit>
100+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageMissingGuidAttribute">
101+
<source>Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</source>
102+
<target state="new">Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</target>
103+
<note />
104+
</trans-unit>
105+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageTitle">
106+
<source>Invalid 'GeneratedComInterfaceAttribute' usage.</source>
107+
<target state="new">Invalid 'GeneratedComInterfaceAttribute' usage.</target>
108+
<note />
109+
</trans-unit>
95110
<trans-unit id="InvalidStringMarshallingConfigurationDescription">
96111
<source>The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' is invalid.</source>
97112
<target state="translated">La configuración de “StringMarshalling” y “StringMarshallingCustomType” no es válida.</target>

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@
9292
<target state="translated">La valeur fournie n’est pas un indicateur connu de l’énumération « ExceptionMarshalling ».</target>
9393
<note />
9494
</trans-unit>
95+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageDescription">
96+
<source>Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</source>
97+
<target state="new">Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</target>
98+
<note />
99+
</trans-unit>
100+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageMissingGuidAttribute">
101+
<source>Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</source>
102+
<target state="new">Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</target>
103+
<note />
104+
</trans-unit>
105+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageTitle">
106+
<source>Invalid 'GeneratedComInterfaceAttribute' usage.</source>
107+
<target state="new">Invalid 'GeneratedComInterfaceAttribute' usage.</target>
108+
<note />
109+
</trans-unit>
95110
<trans-unit id="InvalidStringMarshallingConfigurationDescription">
96111
<source>The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' is invalid.</source>
97112
<target state="translated">La configuration de « StringMarshalling » et de « StringMarshallingCustomType » n’est pas valide.</target>

src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@
9292
<target state="translated">Il valore specificato non è un flag noto dell'enumerazione 'ExceptionMarshalling'.</target>
9393
<note />
9494
</trans-unit>
95+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageDescription">
96+
<source>Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</source>
97+
<target state="new">Interfaces attributed with 'GeneratedComInterfaceAttribute' must be partial and must specify a GUID with 'System.Runtime.InteropServices.GuidAttribute'.</target>
98+
<note />
99+
</trans-unit>
100+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageMissingGuidAttribute">
101+
<source>Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</source>
102+
<target state="new">Interface '{0}' is attributed with 'GeneratedComInterfaceAttribute' but is missing 'System.Runtime.InteropServices.GuidAttribute'.</target>
103+
<note />
104+
</trans-unit>
105+
<trans-unit id="InvalidGeneratedComInterfaceAttributeUsageTitle">
106+
<source>Invalid 'GeneratedComInterfaceAttribute' usage.</source>
107+
<target state="new">Invalid 'GeneratedComInterfaceAttribute' usage.</target>
108+
<note />
109+
</trans-unit>
95110
<trans-unit id="InvalidStringMarshallingConfigurationDescription">
96111
<source>The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' is invalid.</source>
97112
<target state="translated">La configurazione di 'StringMarshalling' e 'StringMarshallingCustomType' non è valida.</target>

0 commit comments

Comments
 (0)