-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new proposed API to Ancillary.Interop (#81063)
Updates the VTableStubGenerator to use the latest version of the proposed API. Co-authored-by: Aaron Robinson <[email protected]> Co-authored-by: Jeremy Koritzinsky <[email protected]>
- Loading branch information
1 parent
6ede02b
commit 4dea84c
Showing
53 changed files
with
1,069 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/InlinedTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// 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; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; | ||
|
||
namespace Microsoft.Interop | ||
{ | ||
internal static class InlinedTypes | ||
{ | ||
/// <summary> | ||
/// Returns the ClassDeclarationSyntax for: | ||
/// <code> | ||
/// public sealed unsafe class ComWrappersUnwrapper : IUnmanagedObjectUnwrapper | ||
/// { | ||
/// public static object GetObjectForUnmanagedWrapper(void* ptr) | ||
/// { | ||
/// return ComWrappers.ComInterfaceDispatch.GetInstance<object>((ComWrappers.ComInterfaceDispatch*)ptr); | ||
/// } | ||
/// } | ||
/// </code> | ||
/// </summary> | ||
public static ClassDeclarationSyntax ComWrappersUnwrapper { get; } = GetComWrappersUnwrapper(); | ||
|
||
public static ClassDeclarationSyntax GetComWrappersUnwrapper() | ||
{ | ||
return ClassDeclaration("ComWrappersUnwrapper") | ||
.AddModifiers(Token(SyntaxKind.SealedKeyword), | ||
Token(SyntaxKind.UnsafeKeyword), | ||
Token(SyntaxKind.StaticKeyword), | ||
Token(SyntaxKind.FileKeyword)) | ||
.AddMembers( | ||
MethodDeclaration( | ||
PredefinedType(Token(SyntaxKind.ObjectKeyword)), | ||
Identifier("GetComObjectForUnmanagedWrapper")) | ||
.AddModifiers(Token(SyntaxKind.PublicKeyword), | ||
Token(SyntaxKind.StaticKeyword)) | ||
.AddParameterListParameters( | ||
Parameter(Identifier("ptr")) | ||
.WithType(PointerType(PredefinedType(Token(SyntaxKind.VoidKeyword))))) | ||
.WithBody(body: Body())); | ||
|
||
static BlockSyntax Body() | ||
{ | ||
var invocation = InvocationExpression( | ||
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, | ||
MemberAccessExpression( | ||
SyntaxKind.SimpleMemberAccessExpression, | ||
IdentifierName("ComWrappers"), | ||
IdentifierName("ComInterfaceDispatch")), | ||
GenericName( | ||
Identifier("GetInstance"), | ||
TypeArgumentList( | ||
SeparatedList<SyntaxNode>( | ||
new[] { PredefinedType(Token(SyntaxKind.ObjectKeyword)) }))))) | ||
.AddArgumentListArguments( | ||
Argument( | ||
null, | ||
Token(SyntaxKind.None), | ||
CastExpression( | ||
PointerType( | ||
QualifiedName( | ||
IdentifierName("ComWrappers"), | ||
IdentifierName("ComInterfaceDispatch"))), | ||
IdentifierName("ptr")))); | ||
|
||
return Block(ReturnStatement(invocation)); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// <code> | ||
/// file static class UnmanagedObjectUnwrapper | ||
/// { | ||
/// public static object GetObjectForUnmanagedWrapper<T>(void* ptr) where T : IUnmanagedObjectUnwrapper | ||
/// { | ||
/// return T.GetObjectForUnmanagedWrapper(ptr); | ||
/// } | ||
/// } | ||
/// </code> | ||
/// </summary> | ||
public static ClassDeclarationSyntax UnmanagedObjectUnwrapper { get; } = GetUnmanagedObjectUnwrapper(); | ||
|
||
private static ClassDeclarationSyntax GetUnmanagedObjectUnwrapper() | ||
{ | ||
const string tUnwrapper = "TUnwrapper"; | ||
return ClassDeclaration("UnmanagedObjectUnwrapper") | ||
.AddModifiers(Token(SyntaxKind.FileKeyword), | ||
Token(SyntaxKind.StaticKeyword)) | ||
.AddMembers( | ||
MethodDeclaration( | ||
PredefinedType(Token(SyntaxKind.ObjectKeyword)), | ||
Identifier("GetObjectForUnmanagedWrapper")) | ||
.AddModifiers(Token(SyntaxKind.PublicKeyword), | ||
Token(SyntaxKind.StaticKeyword)) | ||
.AddTypeParameterListParameters( | ||
TypeParameter(Identifier(tUnwrapper))) | ||
.AddParameterListParameters( | ||
Parameter(Identifier("ptr")) | ||
.WithType(PointerType(PredefinedType(Token(SyntaxKind.VoidKeyword))))) | ||
.AddConstraintClauses(TypeParameterConstraintClause(IdentifierName(tUnwrapper)) | ||
.AddConstraints(TypeConstraint(ParseTypeName(TypeNames.IUnmanagedObjectUnwrapper)))) | ||
.WithBody(body: Body())); | ||
|
||
static BlockSyntax Body() | ||
{ | ||
var invocation = InvocationExpression( | ||
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, | ||
IdentifierName("T"), | ||
IdentifierName("GetObjectForUnmanagedWrapper"))) | ||
.AddArgumentListArguments( | ||
Argument( | ||
null, | ||
Token(SyntaxKind.None), | ||
IdentifierName("ptr"))); | ||
|
||
return Block(ReturnStatement(invocation)); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.