| 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 'package:front_end/src/fasta/scanner.dart' show isUserDefinableOperator; | 7 import 'package:front_end/src/fasta/scanner.dart' show isUserDefinableOperator; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/names.dart' show Selectors; | 10 import '../common/names.dart' show Selectors; |
| (...skipping 4396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4407 } | 4407 } |
| 4408 } | 4408 } |
| 4409 | 4409 |
| 4410 visitLabel(Label node) { | 4410 visitLabel(Label node) { |
| 4411 // Labels are handled by their containing statements/cases. | 4411 // Labels are handled by their containing statements/cases. |
| 4412 } | 4412 } |
| 4413 | 4413 |
| 4414 ResolutionResult visitLabeledStatement(LabeledStatement node) { | 4414 ResolutionResult visitLabeledStatement(LabeledStatement node) { |
| 4415 Statement body = node.statement; | 4415 Statement body = node.statement; |
| 4416 JumpTarget targetElement = getOrDefineTarget(body); | 4416 JumpTarget targetElement = getOrDefineTarget(body); |
| 4417 Map<String, LabelDefinition> labelElements = <String, LabelDefinition>{}; | 4417 Map<String, LabelDefinitionX> labelElements = <String, LabelDefinitionX>{}; |
| 4418 for (Label label in node.labels) { | 4418 for (Label label in node.labels) { |
| 4419 String labelName = label.labelName; | 4419 String labelName = label.labelName; |
| 4420 if (labelElements.containsKey(labelName)) continue; | 4420 if (labelElements.containsKey(labelName)) continue; |
| 4421 LabelDefinition element = targetElement.addLabel(label, labelName); | 4421 LabelDefinition element = targetElement.addLabel(label, labelName); |
| 4422 labelElements[labelName] = element; | 4422 labelElements[labelName] = element; |
| 4423 } | 4423 } |
| 4424 statementScope.enterLabelScope(labelElements); | 4424 statementScope.enterLabelScope(labelElements); |
| 4425 visit(node.statement); | 4425 visit(node.statement); |
| 4426 statementScope.exitLabelScope(); | 4426 statementScope.exitLabelScope(); |
| 4427 labelElements.forEach((String labelName, LabelDefinition element) { | 4427 labelElements.forEach((String labelName, LabelDefinitionX element) { |
| 4428 if (element.isTarget) { | 4428 if (element.isTarget) { |
| 4429 registry.defineLabel(element.label, element); | 4429 registry.defineLabel(element.label, element); |
| 4430 } else { | 4430 } else { |
| 4431 reporter.reportWarningMessage( | 4431 reporter.reportWarningMessage( |
| 4432 element.label, MessageKind.UNUSED_LABEL, {'labelName': labelName}); | 4432 element.label, MessageKind.UNUSED_LABEL, {'labelName': labelName}); |
| 4433 } | 4433 } |
| 4434 }); | 4434 }); |
| 4435 if (!targetElement.isTarget) { | 4435 if (!targetElement.isTarget) { |
| 4436 registry.undefineTarget(body); | 4436 registry.undefineTarget(body); |
| 4437 } | 4437 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4609 } | 4609 } |
| 4610 if (error != null) { | 4610 if (error != null) { |
| 4611 reporter.reportError(error, infos); | 4611 reporter.reportError(error, infos); |
| 4612 } | 4612 } |
| 4613 } | 4613 } |
| 4614 | 4614 |
| 4615 ResolutionResult visitSwitchStatement(SwitchStatement node) { | 4615 ResolutionResult visitSwitchStatement(SwitchStatement node) { |
| 4616 node.expression.accept(this); | 4616 node.expression.accept(this); |
| 4617 | 4617 |
| 4618 JumpTarget breakElement = getOrDefineTarget(node); | 4618 JumpTarget breakElement = getOrDefineTarget(node); |
| 4619 Map<String, LabelDefinition> continueLabels = <String, LabelDefinition>{}; | 4619 Map<String, LabelDefinitionX> continueLabels = <String, LabelDefinitionX>{}; |
| 4620 Set<SwitchCase> switchCasesWithContinues = new Set<SwitchCase>(); | 4620 Set<SwitchCase> switchCasesWithContinues = new Set<SwitchCase>(); |
| 4621 Link<Node> cases = node.cases.nodes; | 4621 Link<Node> cases = node.cases.nodes; |
| 4622 while (!cases.isEmpty) { | 4622 while (!cases.isEmpty) { |
| 4623 SwitchCase switchCase = cases.head; | 4623 SwitchCase switchCase = cases.head; |
| 4624 for (Node labelOrCase in switchCase.labelsAndCases) { | 4624 for (Node labelOrCase in switchCase.labelsAndCases) { |
| 4625 CaseMatch caseMatch = labelOrCase.asCaseMatch(); | 4625 CaseMatch caseMatch = labelOrCase.asCaseMatch(); |
| 4626 if (caseMatch != null) { | 4626 if (caseMatch != null) { |
| 4627 analyzeConstantDeferred(caseMatch.expression); | 4627 analyzeConstantDeferred(caseMatch.expression); |
| 4628 continue; | 4628 continue; |
| 4629 } | 4629 } |
| 4630 Label label = labelOrCase; | 4630 Label label = labelOrCase; |
| 4631 String labelName = label.labelName; | 4631 String labelName = label.labelName; |
| 4632 | 4632 |
| 4633 LabelDefinition existingElement = continueLabels[labelName]; | 4633 LabelDefinitionX existingElement = continueLabels[labelName]; |
| 4634 if (existingElement != null) { | 4634 if (existingElement != null) { |
| 4635 // It's an error if the same label occurs twice in the same switch. | 4635 // It's an error if the same label occurs twice in the same switch. |
| 4636 reporter.reportError( | 4636 reporter.reportError( |
| 4637 reporter.createMessage( | 4637 reporter.createMessage( |
| 4638 label, MessageKind.DUPLICATE_LABEL, {'labelName': labelName}), | 4638 label, MessageKind.DUPLICATE_LABEL, {'labelName': labelName}), |
| 4639 <DiagnosticMessage>[ | 4639 <DiagnosticMessage>[ |
| 4640 reporter.createMessage(existingElement.label, | 4640 reporter.createMessage(existingElement.label, |
| 4641 MessageKind.EXISTING_LABEL, {'labelName': labelName}), | 4641 MessageKind.EXISTING_LABEL, {'labelName': labelName}), |
| 4642 ]); | 4642 ]); |
| 4643 } else { | 4643 } else { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4687 | 4687 |
| 4688 continueLabels.forEach((String key, LabelDefinition label) { | 4688 continueLabels.forEach((String key, LabelDefinition label) { |
| 4689 if (label.isContinueTarget) { | 4689 if (label.isContinueTarget) { |
| 4690 JumpTarget targetElement = label.target; | 4690 JumpTarget targetElement = label.target; |
| 4691 SwitchCase switchCase = targetElement.statement; | 4691 SwitchCase switchCase = targetElement.statement; |
| 4692 switchCasesWithContinues.add(switchCase); | 4692 switchCasesWithContinues.add(switchCase); |
| 4693 } | 4693 } |
| 4694 }); | 4694 }); |
| 4695 | 4695 |
| 4696 // Clean-up unused labels. | 4696 // Clean-up unused labels. |
| 4697 continueLabels.forEach((String key, LabelDefinition label) { | 4697 continueLabels.forEach((String key, LabelDefinitionX label) { |
| 4698 if (!label.isContinueTarget) { | 4698 if (!label.isContinueTarget) { |
| 4699 JumpTarget targetElement = label.target; | 4699 JumpTarget targetElement = label.target; |
| 4700 SwitchCase switchCase = targetElement.statement; | 4700 SwitchCase switchCase = targetElement.statement; |
| 4701 if (!switchCasesWithContinues.contains(switchCase)) { | 4701 if (!switchCasesWithContinues.contains(switchCase)) { |
| 4702 registry.undefineTarget(switchCase); | 4702 registry.undefineTarget(switchCase); |
| 4703 } | 4703 } |
| 4704 registry.undefineLabel(label.label); | 4704 registry.undefineLabel(label.label); |
| 4705 } | 4705 } |
| 4706 }); | 4706 }); |
| 4707 // TODO(15575): We should warn if we can detect a fall through | 4707 // TODO(15575): We should warn if we can detect a fall through |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4818 } | 4818 } |
| 4819 return const NoneResult(); | 4819 return const NoneResult(); |
| 4820 } | 4820 } |
| 4821 } | 4821 } |
| 4822 | 4822 |
| 4823 /// Looks up [name] in [scope] and unwraps the result. | 4823 /// Looks up [name] in [scope] and unwraps the result. |
| 4824 Element lookupInScope( | 4824 Element lookupInScope( |
| 4825 DiagnosticReporter reporter, Node node, Scope scope, String name) { | 4825 DiagnosticReporter reporter, Node node, Scope scope, String name) { |
| 4826 return Elements.unwrap(scope.lookup(name), reporter, node); | 4826 return Elements.unwrap(scope.lookup(name), reporter, node); |
| 4827 } | 4827 } |
| OLD | NEW |