Skip to content
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

Support multi file generation in the Binding generator #43

Merged
merged 4 commits into from
May 9, 2019

Conversation

tannergooding
Copy link
Member

@tannergooding tannergooding commented May 9, 2019

This resolves #30

This updates the ClangSharpPInvokeGenerator to support emitting one file per type (and one file for all methods).

It also updates the generator to only emit required usings and to not emit a class to hold methods if the header file contains no methods.

@tannergooding
Copy link
Member Author

This allows a single pass per translation unit.

This has a side effect of always emitting two files, even if multi-file is not specified (one for the types and one for the methods). I could probably fix this to continue being one file, but it probably needs more thought on how I can do that cleanly.

I did this in a couple stages to validate that nothing regressed in the overall generation story. Notably, the first commit adds support for multi-file generation but just regenerates the code into two files. The second commit then regenerates things split up.

@tannergooding
Copy link
Member Author

Overall, having things split into one file per type allows easier review of changes and makes the output deterministic, rather than dependent on various parse orderings (such as passing in y.h before x.h).


namespace ClangSharpPInvokeGenerator
{
internal sealed class OutputBuilder : IDisposable
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also allow some other interesting configuration options. Such as sorting types or methods before writing them out to the file (which would allow determinism for single-file generation and for the method class file).

@@ -2533,6 +1088,5 @@ public static partial class clang

[DllImport(libraryPath, EntryPoint = "clang_CompileCommand_getMappedSourceContent", CallingConvention = CallingConvention.Cdecl)]
public static extern CXString CompileCommand_getMappedSourceContent(CXCompileCommand param0, uint I);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OutputBuilder also makes it easier to handle these trailing newlines 🎉

@tannergooding tannergooding merged commit 7876c0f into dotnet:master May 9, 2019
@tannergooding tannergooding deleted the multi-file branch May 10, 2019 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider allowing the generator to split the types into one file per type
2 participants