cb7bedf860
The overall strategy is to convert the following:
switch (e) {
l_0: case e0: s_0; break;
l_1: case e1: s_1; continue l_i;
...
l_n: default: s_n; continue l_j;
}
into this:
var label;
switch (e) {
case e0: label = 0; break;
case e1: label = 1; break;
...
default: label = n; break;
}
l: while (true) {
switch (label) {
case 0: s_0; break l;
case 1: s_1; label = i; continue l;
...
case n: s_n; label = j; continue l;
}
}
BUG=http://dartbug.com/8270
R=ngeoffray@google.com
Review URL: https://codereview.chromium.org//14969004
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22838 260f80e4-7a28-3924-810f-c04153c831b5
42 lines
998 B
Dart
42 lines
998 B
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Test nested switch statement using labels.
|
|
|
|
library nested_switch_label;
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
void main() {
|
|
doSwitch(0, ['0', '2:0', '1', 'default']);
|
|
doSwitch(2, ['2:2', '2:1', '2', '1', 'default']);
|
|
}
|
|
|
|
void doSwitch(int target, List expect) {
|
|
List list = [];
|
|
switch (target) {
|
|
outer0: case 0:
|
|
list.add('0');
|
|
continue outer2;
|
|
outer1: case 1:
|
|
list.add('1');
|
|
continue outerDefault;
|
|
outer2: case 2:
|
|
switch (target) {
|
|
inner0: case 0:
|
|
list.add('2:0');
|
|
continue outer1;
|
|
inner2: case 2:
|
|
list.add('2:2');
|
|
continue inner1;
|
|
inner1: case 1:
|
|
list.add('2:1');
|
|
}
|
|
list.add('2');
|
|
continue outer1;
|
|
outerDefault: default:
|
|
list.add('default');
|
|
}
|
|
Expect.listEquals(expect, list);
|
|
} |