You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Translate goto label attached to switch case (#189)
Translates a label atttached to a switch case, from:
```cpp
switch (n) {
target:
case 0:
...
case 1:
...
goto target;
```
to
```rs
switch!(match n {
__v if __v == 0 => 'target: {
...
}
__v if __v == 1 => {
...
goto!('target);
}
```
To make this work, I refactored all switch-analysing functions into a
single struct, called SwitchArm. Now, VisitSwitchStmt first calls
AnalyzeSwitchArms, then iterates over the SwitchArms and generates the
corresponding Rust code. Each SwitchArm has a field called label used
for generating ` __v if __v == 0 => 'target: {`, i.e. a labeled block in
Rust.
The changes in libcc2rs-macros/src/switch.rs are minimal. I added
support for accepting a labeled block in the switch! macro.
0 commit comments