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

Pascal case primitives #565

Closed
wants to merge 3 commits into from
Closed

Conversation

adamski
Copy link
Contributor

@adamski adamski commented Aug 19, 2020

This properly addresses our use case where we want to the default of e.g. MyType______c_char to be MyTypeCChar. The previous PR did not take the c_char type or similar into account, only capitalising the first letter for e.g. MyTypeU32.

Cargo.toml Outdated Show resolved Hide resolved
src/bindgen/config.rs Outdated Show resolved Hide resolved
src/bindgen/ir/opaque.rs Outdated Show resolved Hide resolved
@adamski
Copy link
Contributor Author

adamski commented Aug 20, 2020

So I was thinking about this, and my feeling is that the previous (now merged) PR that allows for different separators, is possibly not that useful (at least I can't think of a use case where someone would want a different character to _).

What we ultimately want is to be able to PascalCase generated types/typedefs. So my proposal is to merge the two (remove underscores and PascalCase primitives), to something like rename_types = "PascalCase". Perhaps a remove_underscores bool in addition to a rename_types rule?

@emilio
Copy link
Collaborator

emilio commented Aug 26, 2020

remove_underscores + rename_types would be the same as mangling_separator = "" and rename_types, right? If so, I think there's no need to change the existing option unless you feel really strongly about it.

@adamski
Copy link
Contributor Author

adamski commented Aug 26, 2020

remove_underscores + rename_types would be the same as mangling_separator = "" and rename_types, right?

Yes, although I'm also suggesting they could be merged into one option.

If so, I think there's no need to change the existing option unless you feel really strongly about it.

OK, I'm just struggling to think of a use case where someone would want a different mangle_seperator to _...

@adamski adamski requested a review from emilio September 2, 2020 16:25
@adamski
Copy link
Contributor Author

adamski commented Sep 14, 2020

@emilio please review the updated changes when you have time. Thank you.

Copy link
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

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

This looks generally good, but I have some nits and one error in to_str. I'm still not a fan of removing an existing option for mangle_separator somewhat arbitrarily, but I guess it's relatively new so it can be fine.

Can you squash the commits too?

src/bindgen/rename.rs Outdated Show resolved Hide resolved
src/bindgen/mangle.rs Outdated Show resolved Hide resolved
src/bindgen/mangle.rs Outdated Show resolved Hide resolved
@adamski adamski force-pushed the pascal-case-primitives branch from 20906d8 to 7e0e2a8 Compare September 20, 2020 20:50
Fix warnings

Tests passed!

Fix refactor mistake

Add #[cfg(test)] to import

Rename to rename_types
@adamski adamski force-pushed the pascal-case-primitives branch from 7e0e2a8 to caf256b Compare September 20, 2020 21:02
@adamski adamski requested a review from emilio September 20, 2020 21:04
@emilio emilio mentioned this pull request Sep 22, 2020
@emilio
Copy link
Collaborator

emilio commented Sep 22, 2020

Thanks! This looks fine. I have a few nits but I addressed them in a follow-up commit in #575.

In particular, the rename_types should probably be on its own subsection of the configuration, otherwise being under [export] seems like you'd rename all the types in here which is not what you're doing. I also added some docs and some integration tests.

@emilio
Copy link
Collaborator

emilio commented Sep 22, 2020

Closing because I merged this in #575

@emilio emilio closed this Sep 22, 2020
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.

2 participants