-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Reuse more Microsoft.Interop.SourceGeneration code in JS generators #74949
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9f6e84c
Move the JavaScript source generators to adopt the Microsoft.Interop.…
jkoritzinsky dcf495c
Refactor out MarshallingInfoParser creation from SignatureContext.
jkoritzinsky 5c8eaa3
Change JSSignatureContext to wrap a SignatureContext instead of dupli…
jkoritzinsky ba8a19d
PR feedback
jkoritzinsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Refactor out MarshallingInfoParser creation from SignatureContext.
- Loading branch information
commit dcf495c09dc3ac8af69bb51d5f97ab3d60fbe224
There are no files selected for viewing
This file contains hidden or 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
57 changes: 57 additions & 0 deletions
57
...System.Runtime.InteropServices/gen/LibraryImportGenerator/DefaultMarshallingInfoParser.cs
This file contains hidden or 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,57 @@ | ||
| // 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.Text; | ||
| using Microsoft.CodeAnalysis; | ||
|
|
||
| namespace Microsoft.Interop | ||
| { | ||
| internal static class DefaultMarshallingInfoParser | ||
| { | ||
| public static MarshallingInfoParser Create(StubEnvironment env, IGeneratorDiagnostics diagnostics, IMethodSymbol method, InteropAttributeData interopAttributeData, AttributeData unparsedAttributeData) | ||
| { | ||
|
|
||
| // Compute the current default string encoding value. | ||
| CharEncoding defaultEncoding = CharEncoding.Undefined; | ||
| if (interopAttributeData.IsUserDefined.HasFlag(InteropAttributeMember.StringMarshalling)) | ||
| { | ||
| defaultEncoding = interopAttributeData.StringMarshalling switch | ||
| { | ||
| StringMarshalling.Utf16 => CharEncoding.Utf16, | ||
| StringMarshalling.Utf8 => CharEncoding.Utf8, | ||
| StringMarshalling.Custom => CharEncoding.Custom, | ||
| _ => CharEncoding.Undefined, // [Compat] Do not assume a specific value | ||
| }; | ||
| } | ||
| else if (interopAttributeData.IsUserDefined.HasFlag(InteropAttributeMember.StringMarshallingCustomType)) | ||
| { | ||
| defaultEncoding = CharEncoding.Custom; | ||
| } | ||
|
|
||
| var defaultInfo = new DefaultMarshallingInfo(defaultEncoding, interopAttributeData.StringMarshallingCustomType); | ||
|
|
||
| var useSiteAttributeParsers = ImmutableArray.Create<IUseSiteAttributeParser>( | ||
| new MarshalAsAttributeParser(env.Compilation, diagnostics, defaultInfo), | ||
| new MarshalUsingAttributeParser(env.Compilation, diagnostics)); | ||
|
|
||
| return new MarshallingInfoParser( | ||
| diagnostics, | ||
| new MethodSignatureElementInfoProvider(env.Compilation, diagnostics, method, useSiteAttributeParsers), | ||
| useSiteAttributeParsers, | ||
| ImmutableArray.Create<IMarshallingInfoAttributeParser>( | ||
| new MarshalAsAttributeParser(env.Compilation, diagnostics, defaultInfo), | ||
| new MarshalUsingAttributeParser(env.Compilation, diagnostics), | ||
| new NativeMarshallingAttributeParser(env.Compilation, diagnostics)), | ||
| ImmutableArray.Create<ITypeBasedMarshallingInfoProvider>( | ||
| new SafeHandleMarshallingInfoProvider(env.Compilation, method.ContainingType), | ||
| new ArrayMarshallingInfoProvider(env.Compilation), | ||
| new CharMarshallingInfoProvider(defaultInfo), | ||
| new StringMarshallingInfoProvider(env.Compilation, diagnostics, unparsedAttributeData, defaultInfo), | ||
| new BooleanMarshallingInfoProvider(), | ||
| new BlittableTypeMarshallingInfoProvider(env.Compilation))); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.