mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-out] introduce a new block for switch cases
This commit is contained in:
@@ -1807,23 +1807,29 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
for case in cases {
|
||||
match case.value {
|
||||
crate::SwitchValue::Integer(value) => {
|
||||
writeln!(self.out, "{}case {}{}:", l2, value, type_postfix)?
|
||||
write!(self.out, "{}case {}{}:", l2, value, type_postfix)?
|
||||
}
|
||||
crate::SwitchValue::Default => writeln!(self.out, "{}default:", l2)?,
|
||||
crate::SwitchValue::Default => write!(self.out, "{}default:", l2)?,
|
||||
}
|
||||
|
||||
let write_block_braces = !(case.fall_through && case.body.is_empty());
|
||||
if write_block_braces {
|
||||
writeln!(self.out, " {{")?;
|
||||
} else {
|
||||
writeln!(self.out)?;
|
||||
}
|
||||
|
||||
for sta in case.body.iter() {
|
||||
self.write_stmt(sta, ctx, l2.next())?;
|
||||
}
|
||||
|
||||
// Write fallthrough comment if the case is fallthrough,
|
||||
// otherwise write a break, if the case is not already
|
||||
// broken out of at the end of its body.
|
||||
if case.fall_through {
|
||||
writeln!(self.out, "{}/* fallthrough */", l2.next())?;
|
||||
} else if case.body.last().map_or(true, |s| !s.is_terminator()) {
|
||||
if !case.fall_through && case.body.last().map_or(true, |s| !s.is_terminator()) {
|
||||
writeln!(self.out, "{}break;", l2.next())?;
|
||||
}
|
||||
|
||||
if write_block_braces {
|
||||
writeln!(self.out, "{}}}", l2)?;
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
|
||||
Reference in New Issue
Block a user