-
Notifications
You must be signed in to change notification settings - Fork 583
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
Fixes #5613 - Generated C++ code issue with keyword "delete" #6441
Conversation
Add function to check if word is cpp_keyword Update ident function to check for potential cpp_keywords
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.
Thanks for this PR.
Some feedback:
lazy_static
is kind of being phased out and being replaced bystd::sync::OnceLock
. See https://github.com/rust-lang-nursery/lazy-static.rs?tab=readme-ov-file#standard-library
You can put the CPP_KEYWORDS OnceLock directly in theis_cpp_keyword
function- This adds a cpp_keywords.json, but this is not usefull, right?
- keywrods needs to be checked after normalizing for
-
. For example there can be an identifierstatic-assert
- regarding the test, the files in tests/syntax are not being generated into C++. Only the ones in tests/cases
An example of test that can be extended with C++ keywords: https://github.com/slint-ui/slint/blob/master/tests/cases/types/structs_keyword.slint - as the CI points out, this currently break if you have a property of function that is a keyword (example,
do
->invoke_do
) looks like the ident function should be called on the whole name rather than on part of the identifier.
Thanks a lot for your patch. Do you think you can do the changes?
Hi. |
-add C++ keyword test to structs_keyword.slint
I see there's still some issues. I'm not sure what should be done to resolve (as the CI points out, this currently break if you have a property of function that is a keyword (example, do -> invoke_do) looks like the ident function should be called on the whole name rather than on part of the identifier.). Could you elaborate on that please? |
Basically, the problem is that we use the output of the ident function and concatenate. slint/internal/compiler/generator/cpp.rs Line 760 in 054035d
slint/internal/compiler/generator/cpp.rs Line 1095 in 054035d
slint/internal/compiler/generator/cpp.rs Line 2565 in 054035d
slint/internal/compiler/generator/cpp.rs Line 2582 in 054035d
slint/internal/compiler/generator/cpp.rs Line 2696 in 054035d
(and maybe other places) In these cases, we should either have a different function to escape the |
@@ -12,6 +12,10 @@ match := Rectangle { | |||
property<bool> test: move.loop == "mod"; | |||
} | |||
|
|||
export struct Name { | |||
delete: image | |||
} |
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.
you can also try to add more stuff such as
struct struct {
delete: image;
}
export global const {
in-out property<struct> return;
}
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.
I added some in new commits. Although in case of for example
export global const{
in-out property<unsigned> atomic_commit;
in-out property<namespace> return;
}
there is
running 1 test
test test_cpp_types_structs_keyword ... FAILED
failures:
---- test_cpp_types_structs_keyword stdout ----
/tmp/.tmpn7hGBG.cpp: In member function ‘const T& char_::global() const’:
/tmp/.tmpn7hGBG.cpp:293:41: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
293 | else if constexpr(std::is_same_v<T, const>) { return *m_globals.global_const.get(); }
| ^~~~~
thread 'test_cpp_types_structs_keyword' panicked at /home/qubi/Projects/slint/target/debug/build/test-driver-cpp-815659352fb91da7/out/test_functions.rs:3100:20:
called `Result::unwrap()` on an `Err` value: "C++ Compilation error (see stdout)"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I'm not sure if this should be addressed or not.
A scenario with concatenated names is resolved with a new function that does what the previous Ident did. |
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.
The problem is that the test was old and relied on the old syntax that generated the last component. But now there are more components added in the test, so the original match
component is no longer generated.
The solution is to keep the match
component the last component in the test. (so move the new struct and component before it)
I changed tests/cases/types/structs_keyword.slint. Now it passes the tests. |
Thanks for all the help from the beginning. It`s my first opensource PR, so it means a lot to me :D |
Seems everything is in order now :D |
Thanks a lot for this PR and fixing all the issues with it! |
Fixes #5613 ChangeLog: C++: generated code adds `_` to the end of identifier that would otherwise be keywords
I added lazy static hashset of all cpp_keywords. Now every ident is checked for potential collidations. If they happen, then
_
is added.