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

Feature explicit case conversion #1108

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

BenFordTytherington
Copy link
Collaborator

Add an attribute for extern blocks which specifies all the items inside can have their names automatically converted to the correct case.

Copy link

codecov bot commented Oct 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (fd558d5) to head (1d3d5e9).

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.
📢 Have feedback on the report? Share it here.

@@ -123,6 +126,15 @@ impl Name {
})
.transpose()?;

match auto_case {
AutoCase::CamelCase => {
Copy link
Collaborator

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 ? 🤔

Copy link
Collaborator Author

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.

Copy link
Collaborator

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
}

Copy link
Collaborator

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
}

Copy link
Collaborator

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.

…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
@BenFordTytherington BenFordTytherington marked this pull request as ready for review October 21, 2024 14:20
…ase instead

- Adds an automatic case conversion to passthrough and naming test
- Adds unit tests to test feature
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