-
Notifications
You must be signed in to change notification settings - Fork 74
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
Feature explicit case conversion #1108
base: main
Are you sure you want to change the base?
Feature explicit case conversion #1108
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1108 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 71 71
Lines 11949 12050 +101
==========================================
+ Hits 11949 12050 +101 ☔ View full report in Codecov by Sentry. |
crates/cxx-qt-gen/src/naming/name.rs
Outdated
@@ -123,6 +126,15 @@ impl Name { | |||
}) | |||
.transpose()?; | |||
|
|||
match auto_case { | |||
AutoCase::CamelCase => { |
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.
@LeonMatthesKDAB did we want to have camelCase and snake_case conversion depending on the block type?
eg a RustQt block you write from the perspective of Rust and we auto convert to C++. And a C++Qt block you write from the perspective of C++ and you auto convert to Rust
#[auto_case]
unsafe extern "RustQt" {
fn function_name(); // ends up as functionName in C++
}
#[auto_case]
unsafe extern "C++Qt" {
fn functionName(); // ends up as function_name in Rust?! (but this is means the rust name is magic?)
}
Or do we already want to introduce the type of the conversion, then leave it up to the developer to decide the direction ?
#[auto_case = Camel]
unsafe extern "RustQt" {
fn function_name(); // ends up as functionName in C++
}
#[auto_case = Snake]
unsafe extern "C++Qt" {
fn functionName(); // ends up as function_name in C++
}
And when do we do the auto conversion ? Do we do it when we see there are no custom cxx_name and rust_name ?
How do we know where to apply it to ? Do we always do it to the cxx_name
and never the rust name ?
Or is the whole thing just #[auto_case]
which just converts any Rust name to a camel case name in C++ ? And never changes the Rust name ? 🤔
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.
My plan was going to be to include both, so like you said camel for rust blocks, and snake for c++ blocks, but then also allowing the developer to specify if they wanted, so that auto_case would be a shorthand.
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.
Right, i just wonder if any of this is confusing if we start modifying effectively the rust_name, or maybe that is fine 🤔
As then the question becomes
#[auto_camel]
unsafe extern "RustQt" {
fn my_function1(); // becomes cxx_name = myFunction1
}
#[auto_camel]
unsafe extern "C++Qt" {
fn myFunction2(); // becomes rust_name my_function2
}
But then this is curious, if you specify the Camel / Snake as opposites.
#[auto_camel = Snake]
unsafe extern "RustQt" {
fn my_function1();
fn myFunction3(); // becomes cxx_name = my_function3
}
#[auto_camel = Camel]
unsafe extern "C++Qt" {
fn myFunction2();
fn my_Function4(); // becomes rust_name = myFunction4
}
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.
Another route to avoid the confusion over whether the "auto" affects the cxx or rust name is to encode that into the attribute. So you could have auto_cxx_case
and auto_rust_case
.
Then this at least makes sense with what it does and gives you full flexibility
#[auto_cxx_case = Snake]
unsafe extern "RustQt" {
fn my_function1();
fn myFunction3(); // becomes cxx_name = my_function3
}
#[auto_rust_case = Camel]
unsafe extern "C++Qt" {
fn myFunction2();
fn my_Function4(); // becomes rust_name = myFunction4
}
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.
So then we could start with #[auto_cxx_case]
and #[auto_rust_case]
which default to Camel and Snake for now. If we need to pick a non-default case later we can still do this without breaking API.
0182795
to
2a847f4
Compare
…nction parsers - Enum has None or CamelCase for now - Attribute syntax is #[auto_case] - Attribute currently has no effect
- Methods, Inherited methods and QSignals can now automatically convert case - Adds 2 basic tests for this functionality
1f84c16
to
7d0e20f
Compare
…ase instead - Adds an automatic case conversion to passthrough and naming test - Adds unit tests to test feature
7d0e20f
to
1d3d5e9
Compare
Add an attribute for extern blocks which specifies all the items inside can have their names automatically converted to the correct case.