mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Allow unsigned integers in switch
This commit is contained in:
committed by
Dzmitry Malyshau
parent
6a57559070
commit
d5fc05e8a4
@@ -1427,11 +1427,18 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
write!(self.out, "switch(")?;
|
||||
self.write_expr(selector, ctx)?;
|
||||
writeln!(self.out, ") {{")?;
|
||||
let type_postfix = match *ctx.info[selector].ty.inner_with(&self.module.types) {
|
||||
crate::TypeInner::Scalar {
|
||||
kind: crate::ScalarKind::Uint,
|
||||
..
|
||||
} => "u",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
// Write all cases
|
||||
let l2 = level.next();
|
||||
for case in cases {
|
||||
writeln!(self.out, "{}case {}:", l2, case.value)?;
|
||||
writeln!(self.out, "{}case {}{}:", l2, case.value, type_postfix)?;
|
||||
|
||||
for sta in case.body.iter() {
|
||||
self.write_stmt(sta, ctx, l2.next())?;
|
||||
|
||||
@@ -1370,13 +1370,24 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
write!(self.out, "switch(")?;
|
||||
self.write_expr(module, selector, func_ctx)?;
|
||||
writeln!(self.out, ") {{")?;
|
||||
let type_postfix = match *func_ctx.info[selector].ty.inner_with(&module.types) {
|
||||
crate::TypeInner::Scalar {
|
||||
kind: crate::ScalarKind::Uint,
|
||||
..
|
||||
} => "u",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
// Write all cases
|
||||
let indent_level_1 = level.next();
|
||||
let indent_level_2 = indent_level_1.next();
|
||||
|
||||
for case in cases {
|
||||
writeln!(self.out, "{}case {}: {{", indent_level_1, case.value)?;
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}case {}{}: {{",
|
||||
indent_level_1, case.value, type_postfix
|
||||
)?;
|
||||
|
||||
if case.fall_through {
|
||||
// Generate each fallthrough case statement in a new block. This is done to
|
||||
|
||||
@@ -1439,10 +1439,17 @@ impl<W: Write> Writer<W> {
|
||||
} => {
|
||||
write!(self.out, "{}switch(", level)?;
|
||||
self.put_expression(selector, &context.expression, true)?;
|
||||
let type_postfix = match *context.expression.resolve_type(selector) {
|
||||
crate::TypeInner::Scalar {
|
||||
kind: crate::ScalarKind::Uint,
|
||||
..
|
||||
} => "u",
|
||||
_ => "",
|
||||
};
|
||||
writeln!(self.out, ") {{")?;
|
||||
let lcase = level.next();
|
||||
for case in cases.iter() {
|
||||
writeln!(self.out, "{}case {}: {{", lcase, case.value)?;
|
||||
writeln!(self.out, "{}case {}{}: {{", lcase, case.value, type_postfix)?;
|
||||
self.put_block(lcase.next(), &case.body, context)?;
|
||||
if !case.fall_through {
|
||||
writeln!(self.out, "{}break;", lcase.next())?;
|
||||
|
||||
@@ -887,6 +887,13 @@ impl<W: Write> Writer<W> {
|
||||
let all_fall_through = cases
|
||||
.iter()
|
||||
.all(|case| case.fall_through && case.body.is_empty());
|
||||
let type_postfix = match *func_ctx.info[selector].ty.inner_with(&module.types) {
|
||||
crate::TypeInner::Scalar {
|
||||
kind: crate::ScalarKind::Uint,
|
||||
..
|
||||
} => "u",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
let l2 = level.next();
|
||||
if !cases.is_empty() {
|
||||
@@ -896,11 +903,11 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
if !all_fall_through && case.fall_through && case.body.is_empty() {
|
||||
write_case = false;
|
||||
write!(self.out, "{}, ", case.value)?;
|
||||
write!(self.out, "{}{}, ", case.value, type_postfix)?;
|
||||
continue;
|
||||
} else {
|
||||
write_case = true;
|
||||
writeln!(self.out, "{}: {{", case.value)?;
|
||||
writeln!(self.out, "{}{}: {{", case.value, type_postfix)?;
|
||||
}
|
||||
|
||||
for sta in case.body.iter() {
|
||||
|
||||
Reference in New Issue
Block a user