-
Notifications
You must be signed in to change notification settings - Fork 157
Don't add is_VARIANT when VARIANT is 'set' or 'clear' and width is 1 #99
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
Conversation
This sounds good to me in principle but I'd hate if this introduced a bug because a vendor decide to map, for example, SET to the value 0. Could you add an assertion to check that if the vendor used CLEAR / SET for the enumeratedValue name then its value must be 0 / 1? |
I knew this would happen. I think it'd be better to rename the bit-level set, clear, is_set, is_clear methods so they don't become ambiguous with the variant-level methods. Hmm, maybe ... set_bit, clear_bit, bit_is_set and bit_is_clear? At least the last two can collide with the is_$variant methods. Of course a vendor could name a variant SET_BIT or BIT_IS_SET but I think the best we can do is reduce the chance of name collisions. cc @whitequark #92 |
@japaric seems really ugly but I have no better solution. |
Another way I just thought is ... using another proxy struct. so you can do |
I don't think collisions are an issue, we could simply deterministically rename anything that can collide. I.e.: SVD |
I think svd2rust already skips automatic The confusion is you can't tell from reading the code if It's a pity there's no obvious way to have the proxies take an argument directly, like |
Err, does it do that? Because it shouldn't. Adding enumeratedValues information should not break existing code.
Either this or the |
I think so... Starting here: For example https://docs.rs/stm32f30x/0.4.1/stm32f30x/gpioa/bsrr/struct._Br11W.html has a |
Ugh, I'll fix that. @adamgreig Want to try to implement the bit proxy plus @whitequark's renaming idea. We can probably skip the renaming for now until it becomes a problem in practice. |
Assuming that both of you are on board with the |
How about Edit: that's only helpful in the write direction, of course. For reading, you could have |
I'd prefer to keep the |
@japaric I would prefer |
👍 for |
Elsewhere svd2rust goes for English word order, so |
If a field enumeratedValues includes variants
set
orclear
, and the field width is 1, then the generated Rust contains a duplicateis_set
oris_clear
method.I think it's reasonable for an SVD file to have a
Clear
variant, in the verb sense, for clearing an interrupt flag in a Flag Clear Register. It gives you aclear()
method on the field, rather thanbit(false)
.This patch skips generating is_VARIANT when this condition is met.