PUBLIC COMMENTS
For possible future work, specialized translations for
well-behaved two-alternative string switches into
if-based structures could be added. Well behaved in
this context either means no fallthroughs or
unconditionally always falling through from the first
alternative into the second.
With two alteratives, there are six cases to consider,
three combinations of "case" and "default" with and
without fallthroughs:
1) case "a": Stmts_a
default: Stmts_default
2) default: Stmts_default
case "a": Stmts_a
3) case "a": Stmts_a
case "b": Stams_b
When there is not a fallthrough, the switch block can
be translated into an if() ... else structure:
1) if(s.equals("a"))
Stmts_a minus any trailing break
else
Stmts_default minus any trailing break
2) if(!s.equals("a"))
Stmts_default minus any trailing break
else
Stmts_a minus any trailing break
3) if(s.equals("a"))
Stmts_a minus any trailing break
else if (s.equals("b"))
Stmts_b minus any trailing break
A trailing break means the last statement on the list
is an unlabeled break.
With a fallthrough from the alternative, an if inside a
block can be used:
1) {
if(s.equals("a"))
{ Stmts_a }
Stmts_default minus any trailing break
}
2) {
if(!s.equals("a"))
{ Stmts_default}
Stmts_a minus any trailing break
}
3) {
boolean $fallthrough = false;
if (s.equals("a") {
Stmts_a
$fallthrough = true;
}
if (s.equals("b") || $fallthrough)
{Stmts_b minus any trailing break}
}
|