[glsl-out] introduce a new block for switch cases

This commit is contained in:
teoxoy
2022-11-17 18:10:19 +01:00
committed by Jim Blandy
parent eccdc0aeb1
commit f36adeefaa
2 changed files with 50 additions and 28 deletions

View File

@@ -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)?