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