OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dart2js.resolution.label_scope; | 5 library dart2js.resolution.label_scope; |
6 | 6 |
7 import '../elements/elements.dart' show | 7 import '../elements/elements.dart' show JumpTarget, LabelDefinition; |
8 JumpTarget, | 8 import '../util/util.dart' show Link; |
9 LabelDefinition; | |
10 import '../util/util.dart' show | |
11 Link; | |
12 | 9 |
13 abstract class LabelScope { | 10 abstract class LabelScope { |
14 LabelScope get outer; | 11 LabelScope get outer; |
15 LabelDefinition lookup(String label); | 12 LabelDefinition lookup(String label); |
16 } | 13 } |
17 | 14 |
18 class LabeledStatementLabelScope implements LabelScope { | 15 class LabeledStatementLabelScope implements LabelScope { |
19 final LabelScope outer; | 16 final LabelScope outer; |
20 final Map<String, LabelDefinition> labels; | 17 final Map<String, LabelDefinition> labels; |
21 LabeledStatementLabelScope(this.outer, this.labels); | 18 LabeledStatementLabelScope(this.outer, this.labels); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 StatementScope() | 55 StatementScope() |
59 : labels = const EmptyLabelScope(), | 56 : labels = const EmptyLabelScope(), |
60 breakTargetStack = const Link<JumpTarget>(), | 57 breakTargetStack = const Link<JumpTarget>(), |
61 continueTargetStack = const Link<JumpTarget>(); | 58 continueTargetStack = const Link<JumpTarget>(); |
62 | 59 |
63 LabelDefinition lookupLabel(String label) { | 60 LabelDefinition lookupLabel(String label) { |
64 return labels.lookup(label); | 61 return labels.lookup(label); |
65 } | 62 } |
66 | 63 |
67 JumpTarget currentBreakTarget() => | 64 JumpTarget currentBreakTarget() => |
68 breakTargetStack.isEmpty ? null : breakTargetStack.head; | 65 breakTargetStack.isEmpty ? null : breakTargetStack.head; |
69 | 66 |
70 JumpTarget currentContinueTarget() => | 67 JumpTarget currentContinueTarget() => |
71 continueTargetStack.isEmpty ? null : continueTargetStack.head; | 68 continueTargetStack.isEmpty ? null : continueTargetStack.head; |
72 | 69 |
73 void enterLabelScope(Map<String, LabelDefinition> elements) { | 70 void enterLabelScope(Map<String, LabelDefinition> elements) { |
74 labels = new LabeledStatementLabelScope(labels, elements); | 71 labels = new LabeledStatementLabelScope(labels, elements); |
75 nestingLevel++; | 72 nestingLevel++; |
76 } | 73 } |
77 | 74 |
78 void exitLabelScope() { | 75 void exitLabelScope() { |
79 nestingLevel--; | 76 nestingLevel--; |
80 labels = labels.outer; | 77 labels = labels.outer; |
81 } | 78 } |
82 | 79 |
83 void enterLoop(JumpTarget element) { | 80 void enterLoop(JumpTarget element) { |
84 breakTargetStack = breakTargetStack.prepend(element); | 81 breakTargetStack = breakTargetStack.prepend(element); |
85 continueTargetStack = continueTargetStack.prepend(element); | 82 continueTargetStack = continueTargetStack.prepend(element); |
86 nestingLevel++; | 83 nestingLevel++; |
87 } | 84 } |
88 | 85 |
89 void exitLoop() { | 86 void exitLoop() { |
90 nestingLevel--; | 87 nestingLevel--; |
91 breakTargetStack = breakTargetStack.tail; | 88 breakTargetStack = breakTargetStack.tail; |
92 continueTargetStack = continueTargetStack.tail; | 89 continueTargetStack = continueTargetStack.tail; |
93 } | 90 } |
94 | 91 |
95 void enterSwitch(JumpTarget breakElement, | 92 void enterSwitch( |
96 Map<String, LabelDefinition> continueElements) { | 93 JumpTarget breakElement, Map<String, LabelDefinition> continueElements) { |
97 breakTargetStack = breakTargetStack.prepend(breakElement); | 94 breakTargetStack = breakTargetStack.prepend(breakElement); |
98 labels = new SwitchLabelScope(labels, continueElements); | 95 labels = new SwitchLabelScope(labels, continueElements); |
99 nestingLevel++; | 96 nestingLevel++; |
100 } | 97 } |
101 | 98 |
102 void exitSwitch() { | 99 void exitSwitch() { |
103 nestingLevel--; | 100 nestingLevel--; |
104 breakTargetStack = breakTargetStack.tail; | 101 breakTargetStack = breakTargetStack.tail; |
105 labels = labels.outer; | 102 labels = labels.outer; |
106 } | 103 } |
107 } | 104 } |
OLD | NEW |