| 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.common; | 5 library dart2js.resolution.common; |
| 6 | 6 |
| 7 import '../common/resolution.dart' show | 7 import '../common/resolution.dart' show |
| 8 Resolution; | 8 Resolution; |
| 9 import '../common/tasks.dart' show | 9 import '../common/tasks.dart' show |
| 10 DeferredAction; | 10 DeferredAction; |
| 11 import '../compiler.dart' show | 11 import '../compiler.dart' show |
| 12 Compiler; | 12 Compiler; |
| 13 import '../diagnostics/diagnostic_listener.dart' show | 13 import '../diagnostics/diagnostic_listener.dart' show |
| 14 DiagnosticMessage; | 14 DiagnosticMessage, |
| 15 DiagnosticReporter; |
| 15 import '../diagnostics/messages.dart' show | 16 import '../diagnostics/messages.dart' show |
| 16 MessageKind; | 17 MessageKind; |
| 17 import '../diagnostics/spannable.dart' show | 18 import '../diagnostics/spannable.dart' show |
| 18 Spannable; | 19 Spannable; |
| 19 import '../elements/elements.dart'; | 20 import '../elements/elements.dart'; |
| 20 import '../tree/tree.dart'; | 21 import '../tree/tree.dart'; |
| 21 | 22 |
| 22 import 'registry.dart' show | 23 import 'registry.dart' show |
| 23 ResolutionRegistry; | 24 ResolutionRegistry; |
| 24 import 'scope.dart' show | 25 import 'scope.dart' show |
| 25 Scope; | 26 Scope; |
| 26 import 'type_resolver.dart' show | 27 import 'type_resolver.dart' show |
| 27 TypeResolver; | 28 TypeResolver; |
| 28 | 29 |
| 29 class CommonResolverVisitor<R> extends Visitor<R> { | 30 class CommonResolverVisitor<R> extends Visitor<R> { |
| 30 final Compiler compiler; | 31 final Compiler compiler; |
| 31 | 32 |
| 32 CommonResolverVisitor(Compiler this.compiler); | 33 CommonResolverVisitor(Compiler this.compiler); |
| 33 | 34 |
| 35 DiagnosticReporter get reporter => compiler.reporter; |
| 36 |
| 34 Resolution get resolution => compiler.resolution; | 37 Resolution get resolution => compiler.resolution; |
| 35 | 38 |
| 36 R visitNode(Node node) { | 39 R visitNode(Node node) { |
| 37 return compiler.internalError(node, | 40 return reporter.internalError(node, |
| 38 'internal error: Unhandled node: ${node.getObjectDescription()}'); | 41 'internal error: Unhandled node: ${node.getObjectDescription()}'); |
| 39 } | 42 } |
| 40 | 43 |
| 41 R visitEmptyStatement(Node node) => null; | 44 R visitEmptyStatement(Node node) => null; |
| 42 | 45 |
| 43 /** Convenience method for visiting nodes that may be null. */ | 46 /** Convenience method for visiting nodes that may be null. */ |
| 44 R visit(Node node) => (node == null) ? null : node.accept(this); | 47 R visit(Node node) => (node == null) ? null : node.accept(this); |
| 45 | 48 |
| 46 void addDeferredAction(Element element, DeferredAction action) { | 49 void addDeferredAction(Element element, DeferredAction action) { |
| 47 compiler.enqueuer.resolution.addDeferredAction(element, action); | 50 compiler.enqueuer.resolution.addDeferredAction(element, action); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 72 if (existing != element) { | 75 if (existing != element) { |
| 73 reportDuplicateDefinition(element.name, element, existing); | 76 reportDuplicateDefinition(element.name, element, existing); |
| 74 } | 77 } |
| 75 } | 78 } |
| 76 | 79 |
| 77 void checkLocalDefinitionName(Node node, Element element) { | 80 void checkLocalDefinitionName(Node node, Element element) { |
| 78 if (currentAsyncMarker != AsyncMarker.SYNC) { | 81 if (currentAsyncMarker != AsyncMarker.SYNC) { |
| 79 if (element.name == 'yield' || | 82 if (element.name == 'yield' || |
| 80 element.name == 'async' || | 83 element.name == 'async' || |
| 81 element.name == 'await') { | 84 element.name == 'await') { |
| 82 compiler.reportErrorMessage( | 85 reporter.reportErrorMessage( |
| 83 node, MessageKind.ASYNC_KEYWORD_AS_IDENTIFIER, | 86 node, MessageKind.ASYNC_KEYWORD_AS_IDENTIFIER, |
| 84 {'keyword': element.name, | 87 {'keyword': element.name, |
| 85 'modifier': currentAsyncMarker}); | 88 'modifier': currentAsyncMarker}); |
| 86 } | 89 } |
| 87 } | 90 } |
| 88 } | 91 } |
| 89 | 92 |
| 90 /// Register [node] as the definition of [element]. | 93 /// Register [node] as the definition of [element]. |
| 91 void defineLocalVariable(Node node, LocalVariableElement element) { | 94 void defineLocalVariable(Node node, LocalVariableElement element) { |
| 92 if (element == null) { | 95 if (element == null) { |
| 93 throw compiler.internalError(node, 'element is null'); | 96 throw reporter.internalError(node, 'element is null'); |
| 94 } | 97 } |
| 95 checkLocalDefinitionName(node, element); | 98 checkLocalDefinitionName(node, element); |
| 96 registry.defineElement(node, element); | 99 registry.defineElement(node, element); |
| 97 } | 100 } |
| 98 | 101 |
| 99 void reportDuplicateDefinition(String name, | 102 void reportDuplicateDefinition(String name, |
| 100 Spannable definition, | 103 Spannable definition, |
| 101 Spannable existing) { | 104 Spannable existing) { |
| 102 compiler.reportError( | 105 reporter.reportError( |
| 103 compiler.createMessage( | 106 reporter.createMessage( |
| 104 definition, | 107 definition, |
| 105 MessageKind.DUPLICATE_DEFINITION, | 108 MessageKind.DUPLICATE_DEFINITION, |
| 106 {'name': name}), | 109 {'name': name}), |
| 107 <DiagnosticMessage>[ | 110 <DiagnosticMessage>[ |
| 108 compiler.createMessage( | 111 reporter.createMessage( |
| 109 existing, | 112 existing, |
| 110 MessageKind.EXISTING_DEFINITION, | 113 MessageKind.EXISTING_DEFINITION, |
| 111 {'name': name}), | 114 {'name': name}), |
| 112 ]); | 115 ]); |
| 113 } | 116 } |
| 114 } | 117 } |
| OLD | NEW |