Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.members; | 5 library dart2js.resolution.members; |
| 6 | 6 |
| 7 import 'dart:collection'; | |
| 8 | |
| 7 import '../common.dart'; | 9 import '../common.dart'; |
| 8 import '../common/names.dart' show Selectors; | 10 import '../common/names.dart' show Selectors; |
| 9 import '../common/resolution.dart' show Resolution; | 11 import '../common/resolution.dart' show Resolution; |
| 10 import '../compile_time_constants.dart'; | 12 import '../compile_time_constants.dart'; |
| 11 import '../constants/constructors.dart' | 13 import '../constants/constructors.dart' |
| 12 show RedirectingFactoryConstantConstructor; | 14 show RedirectingFactoryConstantConstructor; |
| 13 import '../constants/expressions.dart'; | 15 import '../constants/expressions.dart'; |
| 14 import '../constants/values.dart'; | 16 import '../constants/values.dart'; |
| 15 import '../core_types.dart'; | 17 import '../core_types.dart'; |
| 16 import '../elements/resolution_types.dart'; | 18 import '../elements/resolution_types.dart'; |
| (...skipping 4577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4594 if (error != null) { | 4596 if (error != null) { |
| 4595 reporter.reportError(error, infos); | 4597 reporter.reportError(error, infos); |
| 4596 } | 4598 } |
| 4597 } | 4599 } |
| 4598 | 4600 |
| 4599 ResolutionResult visitSwitchStatement(SwitchStatement node) { | 4601 ResolutionResult visitSwitchStatement(SwitchStatement node) { |
| 4600 node.expression.accept(this); | 4602 node.expression.accept(this); |
| 4601 | 4603 |
| 4602 JumpTarget breakElement = getOrDefineTarget(node); | 4604 JumpTarget breakElement = getOrDefineTarget(node); |
| 4603 Map<String, LabelDefinition> continueLabels = <String, LabelDefinition>{}; | 4605 Map<String, LabelDefinition> continueLabels = <String, LabelDefinition>{}; |
| 4606 Set<SwitchCase> switchCasesWithContinues = new HashSet<SwitchCase>(); | |
|
sra1
2017/02/07 01:05:06
I'd just say new Set and avoid the import.
Emily Fortuna
2017/02/07 01:30:56
Done.
| |
| 4604 Link<Node> cases = node.cases.nodes; | 4607 Link<Node> cases = node.cases.nodes; |
| 4605 while (!cases.isEmpty) { | 4608 while (!cases.isEmpty) { |
| 4606 SwitchCase switchCase = cases.head; | 4609 SwitchCase switchCase = cases.head; |
| 4607 for (Node labelOrCase in switchCase.labelsAndCases) { | 4610 for (Node labelOrCase in switchCase.labelsAndCases) { |
| 4608 CaseMatch caseMatch = labelOrCase.asCaseMatch(); | 4611 CaseMatch caseMatch = labelOrCase.asCaseMatch(); |
| 4609 if (caseMatch != null) { | 4612 if (caseMatch != null) { |
| 4610 analyzeConstantDeferred(caseMatch.expression); | 4613 analyzeConstantDeferred(caseMatch.expression); |
| 4611 continue; | 4614 continue; |
| 4612 } | 4615 } |
| 4613 Label label = labelOrCase; | 4616 Label label = labelOrCase; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4661 } | 4664 } |
| 4662 | 4665 |
| 4663 addDeferredAction(enclosingElement, () { | 4666 addDeferredAction(enclosingElement, () { |
| 4664 checkCaseExpressions(node); | 4667 checkCaseExpressions(node); |
| 4665 }); | 4668 }); |
| 4666 | 4669 |
| 4667 statementScope.enterSwitch(breakElement, continueLabels); | 4670 statementScope.enterSwitch(breakElement, continueLabels); |
| 4668 node.cases.accept(this); | 4671 node.cases.accept(this); |
| 4669 statementScope.exitSwitch(); | 4672 statementScope.exitSwitch(); |
| 4670 | 4673 |
| 4674 continueLabels.forEach((String key, LabelDefinition label) { | |
| 4675 if (label.isContinueTarget) { | |
| 4676 JumpTarget targetElement = label.target; | |
| 4677 SwitchCase switchCase = targetElement.statement; | |
| 4678 switchCasesWithContinues.add(switchCase); | |
| 4679 } | |
| 4680 }); | |
| 4681 | |
| 4671 // Clean-up unused labels. | 4682 // Clean-up unused labels. |
| 4672 continueLabels.forEach((String key, LabelDefinition label) { | 4683 continueLabels.forEach((String key, LabelDefinition label) { |
| 4673 if (!label.isContinueTarget) { | 4684 if (!label.isContinueTarget) { |
| 4674 JumpTarget targetElement = label.target; | 4685 JumpTarget targetElement = label.target; |
| 4675 SwitchCase switchCase = targetElement.statement; | 4686 SwitchCase switchCase = targetElement.statement; |
| 4676 registry.undefineTarget(switchCase); | 4687 if (!switchCasesWithContinues.contains(switchCase)) { |
| 4688 registry.undefineTarget(switchCase); | |
| 4689 } | |
| 4677 registry.undefineLabel(label.label); | 4690 registry.undefineLabel(label.label); |
| 4678 } | 4691 } |
| 4679 }); | 4692 }); |
| 4680 // TODO(15575): We should warn if we can detect a fall through | 4693 // TODO(15575): We should warn if we can detect a fall through |
| 4681 // error. | 4694 // error. |
| 4682 return const NoneResult(); | 4695 return const NoneResult(); |
| 4683 } | 4696 } |
| 4684 | 4697 |
| 4685 ResolutionResult visitSwitchCase(SwitchCase node) { | 4698 ResolutionResult visitSwitchCase(SwitchCase node) { |
| 4686 node.labelsAndCases.accept(this); | 4699 node.labelsAndCases.accept(this); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4791 } | 4804 } |
| 4792 return const NoneResult(); | 4805 return const NoneResult(); |
| 4793 } | 4806 } |
| 4794 } | 4807 } |
| 4795 | 4808 |
| 4796 /// Looks up [name] in [scope] and unwraps the result. | 4809 /// Looks up [name] in [scope] and unwraps the result. |
| 4797 Element lookupInScope( | 4810 Element lookupInScope( |
| 4798 DiagnosticReporter reporter, Node node, Scope scope, String name) { | 4811 DiagnosticReporter reporter, Node node, Scope scope, String name) { |
| 4799 return Elements.unwrap(scope.lookup(name), reporter, node); | 4812 return Elements.unwrap(scope.lookup(name), reporter, node); |
| 4800 } | 4813 } |
| OLD | NEW |