-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Remove PointerNativeTypeAssignmentRewriter by introducing a separate local with the exact type and assigning to/from it #107219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…local with the exact type and assigning to/from it This removes our syntax rewriting, one of the main blockers for us to move to StringBuilder/string based codegen.
|
Tagging subscribers to this area: @dotnet/interop-contrib |
|
This PR is ready for review |
| // <nativeIdentifier> = <convertToUnmanaged>; | ||
| var assignment = AssignmentExpression( | ||
| SyntaxKind.SimpleAssignmentExpression, | ||
| IdentifierName(nativeIdentifier), | ||
| convertToUnmanaged); | ||
|
|
||
| ExpressionSyntax assignment; | ||
|
|
||
| if (unmanagedType is PointerTypeInfo pointer) | ||
| // For some of our exception marshallers, our marshaller returns nint for pointer types. | ||
| // As a result, we need to insert a cast here in case we're in that scenario (which we can't detect specifically). | ||
| if (unmanagedType is PointerTypeInfo ptrType) | ||
| { | ||
| // <nativeIdentifier> = (<nativeType>)<convertToUnmanaged>; | ||
| assignment = AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, | ||
| IdentifierName(nativeIdentifier), | ||
| CastExpression(ptrType.Syntax, convertToUnmanaged)); | ||
| } | ||
| else | ||
| { | ||
| var rewriter = new PointerNativeTypeAssignmentRewriter(assignment.Right.ToString(), (PointerTypeSyntax)pointer.Syntax); | ||
| assignment = (AssignmentExpressionSyntax)rewriter.Visit(assignment); | ||
| // <nativeIdentifier> = <convertToUnmanaged>; | ||
| assignment = AssignmentExpression( | ||
| SyntaxKind.SimpleAssignmentExpression, | ||
| IdentifierName(nativeIdentifier), | ||
| convertToUnmanaged); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need anything like this for native marshalling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need this for unmarshalling because we only hit it in a specific (due to us artificially resolving the marshaller) scenario. We don't put ourselves into that situation in the native->managed case.
…local with the exact type and assigning to/from it (dotnet#107219)
…local with the exact type and assigning to/from it (dotnet#107219)
…local with the exact type and assigning to/from it (dotnet#107219)
This removes our syntax rewriting, one of the main blockers for us to move to StringBuilder/string based codegen.
Contributes to #95882