Skip to content

Commit 0717eda

Browse files
Create skeleton for the ComInterfaceGenerator (#80887)
Co-authored-by: Jeff Handley <[email protected]>
1 parent 1c4cc74 commit 0717eda

20 files changed

+672
-42
lines changed

docs/project/list-of-diagnostics.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
202202
| __`SYSLIB1088`__ | _`SYSLIB1070`-`SYSLIB1089` reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator._ |
203203
| __`SYSLIB1089`__ | _`SYSLIB1070`-`SYSLIB1089` reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator._ |
204204
| __`SYSLIB1090`__ | Invalid 'GeneratedComInterfaceAttribute' usage |
205+
| __`SYSLIB1091`__ | Method is declared in different partial declaration than the 'GeneratedComInterface' attribute. |
206+
| __`SYSLIB1092`__ | _`SYSLIB1092`-`SYSLIB1099` reserved for Microsoft.Interop.ComInteropGenerator._ |
207+
| __`SYSLIB1093`__ | _`SYSLIB1092`-`SYSLIB1099` reserved for Microsoft.Interop.ComInteropGenerator._ |
208+
| __`SYSLIB1094`__ | _`SYSLIB1092`-`SYSLIB1099` reserved for Microsoft.Interop.ComInteropGenerator._ |
209+
| __`SYSLIB1095`__ | _`SYSLIB1092`-`SYSLIB1099` reserved for Microsoft.Interop.ComInteropGenerator._ |
210+
| __`SYSLIB1096`__ | _`SYSLIB1092`-`SYSLIB1099` reserved for Microsoft.Interop.ComInteropGenerator._ |
211+
| __`SYSLIB1097`__ | _`SYSLIB1092`-`SYSLIB1099` reserved for Microsoft.Interop.ComInteropGenerator._ |
212+
| __`SYSLIB1098`__ | _`SYSLIB1092`-`SYSLIB1099` reserved for Microsoft.Interop.ComInteropGenerator._ |
213+
| __`SYSLIB1099`__ | _`SYSLIB1092`-`SYSLIB1099` reserved for Microsoft.Interop.ComInteropGenerator._ |
205214

206215

207216
### Diagnostic Suppressions (`SYSLIBSUPPRESS****`)

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

Lines changed: 356 additions & 0 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
@@ -20,6 +20,7 @@ public class Ids
2020
public const string InvalidLibraryImportAttributeUsage = Prefix + "1050";
2121
public const string TypeNotSupported = Prefix + "1051";
2222
public const string ConfigurationNotSupported = Prefix + "1052";
23+
public const string MethodNotDeclaredInAttributedInterface = Prefix + "1091";
2324
}
2425

2526
private const string Category = "ComInterfaceGenerator";
@@ -154,6 +155,16 @@ public class Ids
154155
isEnabledByDefault: true,
155156
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
156157

158+
public static readonly DiagnosticDescriptor MethodNotDeclaredInAttributedInterface =
159+
new DiagnosticDescriptor(
160+
Ids.MethodNotDeclaredInAttributedInterface,
161+
GetResourceString(nameof(SR.MethodNotDeclaredInAttributedInterfaceTitle)),
162+
GetResourceString(nameof(SR.MethodNotDeclaredInAttributedInterfaceMessage)),
163+
Category,
164+
DiagnosticSeverity.Error,
165+
isEnabledByDefault: true,
166+
description: GetResourceString(nameof(SR.MethodNotDeclaredInAttributedInterfaceDescription)));
167+
157168

158169
private readonly List<Diagnostic> _diagnostics = new List<Diagnostic>();
159170

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.CodeAnalysis;
5+
using Microsoft.CodeAnalysis.CSharp.Syntax;
6+
using System;
7+
8+
namespace Microsoft.Interop
9+
{
10+
internal sealed record IncrementalMethodStubGenerationContext(
11+
SignatureContext SignatureContext,
12+
ContainingSyntaxContext ContainingSyntaxContext,
13+
ContainingSyntax StubMethodSyntaxTemplate,
14+
MethodSignatureDiagnosticLocations DiagnosticLocation,
15+
SequenceEqualImmutableArray<FunctionPointerUnmanagedCallingConventionSyntax> CallingConvention,
16+
VirtualMethodIndexData VtableIndexData,
17+
MarshallingInfo ExceptionMarshallingInfo,
18+
MarshallingGeneratorFactoryKey<(TargetFramework TargetFramework, Version TargetFrameworkVersion)> ManagedToUnmanagedGeneratorFactory,
19+
MarshallingGeneratorFactoryKey<(TargetFramework TargetFramework, Version TargetFrameworkVersion)> UnmanagedToManagedGeneratorFactory,
20+
ManagedTypeInfo TypeKeyOwner,
21+
SequenceEqualImmutableArray<Diagnostic> Diagnostics);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Collections.Immutable;
7+
using System.Text;
8+
using Microsoft.CodeAnalysis;
9+
10+
namespace Microsoft.Interop
11+
{
12+
internal static class IncrementalValuesProviderExtensions
13+
{
14+
public static IncrementalValuesProvider<(T Left, U Right)> Zip<T, U>(this IncrementalValuesProvider<T> left, IncrementalValuesProvider<U> right)
15+
{
16+
return left
17+
.Collect()
18+
.Combine(right.Collect())
19+
.SelectMany((data, ct) =>
20+
{
21+
if (data.Left.Length != data.Right.Length)
22+
{
23+
throw new InvalidOperationException("The two value providers must provide the same number of values.");
24+
}
25+
ImmutableArray<(T, U)>.Builder builder = ImmutableArray.CreateBuilder<(T, U)>(data.Left.Length);
26+
for (int i = 0; i < data.Left.Length; i++)
27+
{
28+
builder.Add((data.Left[i], data.Right[i]));
29+
}
30+
return builder.MoveToImmutable();
31+
});
32+
}
33+
}
34+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,13 @@
207207
<data name="InterfaceTypeNotSupportedMessage" xml:space="preserve">
208208
<value>Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'.</value>
209209
</data>
210+
<data name="MethodNotDeclaredInAttributedInterfaceDescription" xml:space="preserve">
211+
<value>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.</value>
212+
</data>
213+
<data name="MethodNotDeclaredInAttributedInterfaceMessage" xml:space="preserve">
214+
<value>The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</value>
215+
</data>
216+
<data name="MethodNotDeclaredInAttributedInterfaceTitle" xml:space="preserve">
217+
<value>Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</value>
218+
</data>
210219
</root>

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
@@ -112,6 +112,21 @@
112112
<target state="translated">Neplatné použití VirtualMethodIndexAttribute</target>
113113
<note />
114114
</trans-unit>
115+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceDescription">
116+
<source>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.</source>
117+
<target state="new">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.</target>
118+
<note />
119+
</trans-unit>
120+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceMessage">
121+
<source>The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</source>
122+
<target state="new">The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</target>
123+
<note />
124+
</trans-unit>
125+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceTitle">
126+
<source>Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</source>
127+
<target state="new">Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</target>
128+
<note />
129+
</trans-unit>
115130
<trans-unit id="TypeNotSupportedDescription">
116131
<source>For types that are not supported by source-generated P/Invokes, the resulting P/Invoke will rely on the underlying runtime to marshal the specified type.</source>
117132
<target state="translated">U typů, které nejsou podporovány zdrojem generovanými voláními P/Invoke, bude výsledné volání P/Invoke záviset na podkladovém modulu runtime, aby určený typ zařadil.</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
@@ -112,6 +112,21 @@
112112
<target state="translated">Ungültige Verwendung von „VirtualMethodIndexAttribute“</target>
113113
<note />
114114
</trans-unit>
115+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceDescription">
116+
<source>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.</source>
117+
<target state="new">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.</target>
118+
<note />
119+
</trans-unit>
120+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceMessage">
121+
<source>The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</source>
122+
<target state="new">The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</target>
123+
<note />
124+
</trans-unit>
125+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceTitle">
126+
<source>Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</source>
127+
<target state="new">Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</target>
128+
<note />
129+
</trans-unit>
115130
<trans-unit id="TypeNotSupportedDescription">
116131
<source>For types that are not supported by source-generated P/Invokes, the resulting P/Invoke will rely on the underlying runtime to marshal the specified type.</source>
117132
<target state="translated">Bei Typen, die von dquellgenerierten P/Invokes nicht unterstützt werden, basiert der resultierende P/Invoke auf der zugrunde liegenden Laufzeit, um den angegebenen Typ zu marshallen.</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
@@ -112,6 +112,21 @@
112112
<target state="translated">Uso de ”VirtualMethodIndexAttribute” no válido</target>
113113
<note />
114114
</trans-unit>
115+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceDescription">
116+
<source>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.</source>
117+
<target state="new">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.</target>
118+
<note />
119+
</trans-unit>
120+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceMessage">
121+
<source>The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</source>
122+
<target state="new">The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</target>
123+
<note />
124+
</trans-unit>
125+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceTitle">
126+
<source>Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</source>
127+
<target state="new">Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</target>
128+
<note />
129+
</trans-unit>
115130
<trans-unit id="TypeNotSupportedDescription">
116131
<source>For types that are not supported by source-generated P/Invokes, the resulting P/Invoke will rely on the underlying runtime to marshal the specified type.</source>
117132
<target state="translated">Para los tipos que no son compatibles con P/Invokes de un generador de código fuente, el P/Invoke resultante se basará en el entorno de ejecución subyacente para serializar las referencias del tipo especificado.</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
@@ -112,6 +112,21 @@
112112
<target state="translated">Utilisation de « VirtualMethodIndexAttribute » non valide</target>
113113
<note />
114114
</trans-unit>
115+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceDescription">
116+
<source>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.</source>
117+
<target state="new">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.</target>
118+
<note />
119+
</trans-unit>
120+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceMessage">
121+
<source>The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</source>
122+
<target state="new">The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</target>
123+
<note />
124+
</trans-unit>
125+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceTitle">
126+
<source>Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</source>
127+
<target state="new">Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</target>
128+
<note />
129+
</trans-unit>
115130
<trans-unit id="TypeNotSupportedDescription">
116131
<source>For types that are not supported by source-generated P/Invokes, the resulting P/Invoke will rely on the underlying runtime to marshal the specified type.</source>
117132
<target state="translated">Pour les types qui ne sont pas pris en charge par les P/Invok générés par la source, le P/Invoke résultant se base sur le runtime sous-jacent pour marshaler le type spécifié.</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
@@ -112,6 +112,21 @@
112112
<target state="translated">Utilizzo di 'VirtualMethodIndexAttribute' non valido</target>
113113
<note />
114114
</trans-unit>
115+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceDescription">
116+
<source>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.</source>
117+
<target state="new">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.</target>
118+
<note />
119+
</trans-unit>
120+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceMessage">
121+
<source>The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</source>
122+
<target state="new">The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</target>
123+
<note />
124+
</trans-unit>
125+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceTitle">
126+
<source>Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</source>
127+
<target state="new">Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</target>
128+
<note />
129+
</trans-unit>
115130
<trans-unit id="TypeNotSupportedDescription">
116131
<source>For types that are not supported by source-generated P/Invokes, the resulting P/Invoke will rely on the underlying runtime to marshal the specified type.</source>
117132
<target state="translated">Per i tipi non supportati da P/Invoke generati dall'origine, il P/Invoke risultante si baserà sul runtime sottostante per effettuare il marshalling del tipo specificato.</target>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@
112112
<target state="translated">'VirtualMethodIndexAttribute' の使用法が無効です</target>
113113
<note />
114114
</trans-unit>
115+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceDescription">
116+
<source>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.</source>
117+
<target state="new">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.</target>
118+
<note />
119+
</trans-unit>
120+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceMessage">
121+
<source>The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</source>
122+
<target state="new">The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</target>
123+
<note />
124+
</trans-unit>
125+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceTitle">
126+
<source>Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</source>
127+
<target state="new">Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</target>
128+
<note />
129+
</trans-unit>
115130
<trans-unit id="TypeNotSupportedDescription">
116131
<source>For types that are not supported by source-generated P/Invokes, the resulting P/Invoke will rely on the underlying runtime to marshal the specified type.</source>
117132
<target state="translated">ソース生成済みの P/Invoke でサポートされていない型である場合、生成された P/Invoke は、基礎となるなるランタイムに依存して、指定された型をマーシャリングします。</target>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@
112112
<target state="translated">잘못된 'VirtualMethodIndexAttribute' 사용</target>
113113
<note />
114114
</trans-unit>
115+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceDescription">
116+
<source>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.</source>
117+
<target state="new">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.</target>
118+
<note />
119+
</trans-unit>
120+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceMessage">
121+
<source>The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</source>
122+
<target state="new">The method '{0}' is declared on a different partial definition of the interface '{1}' than the definition that has the 'GeneratedComInterface' attribute</target>
123+
<note />
124+
</trans-unit>
125+
<trans-unit id="MethodNotDeclaredInAttributedInterfaceTitle">
126+
<source>Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</source>
127+
<target state="new">Method is declared in different partial declaration than the 'GeneratedComInterface' attribute.</target>
128+
<note />
129+
</trans-unit>
115130
<trans-unit id="TypeNotSupportedDescription">
116131
<source>For types that are not supported by source-generated P/Invokes, the resulting P/Invoke will rely on the underlying runtime to marshal the specified type.</source>
117132
<target state="translated">소스 생성 P/Invoke에서 지원하지 않는 형식의 경우 결과 P/Invoke는 기본 런타임에 의존하여 지정된 형식을 마샬링합니다.</target>

0 commit comments

Comments
 (0)