| 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.parser.node_listener; | 5 library dart2js.parser.node_listener; |
| 6 | 6 |
| 7 import '../diagnostics/diagnostic_listener.dart'; | 7 import '../diagnostics/diagnostic_listener.dart'; |
| 8 import '../diagnostics/messages.dart'; | 8 import '../diagnostics/messages.dart'; |
| 9 import '../diagnostics/spannable.dart' show | 9 import '../diagnostics/spannable.dart' show |
| 10 Spannable, | 10 Spannable, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 import '../util/util.dart' show | 24 import '../util/util.dart' show |
| 25 Link; | 25 Link; |
| 26 | 26 |
| 27 import 'element_listener.dart' show | 27 import 'element_listener.dart' show |
| 28 ElementListener; | 28 ElementListener; |
| 29 import 'partial_elements.dart' show | 29 import 'partial_elements.dart' show |
| 30 PartialFunctionElement; | 30 PartialFunctionElement; |
| 31 | 31 |
| 32 class NodeListener extends ElementListener { | 32 class NodeListener extends ElementListener { |
| 33 NodeListener( | 33 NodeListener( |
| 34 DiagnosticListener listener, | 34 DiagnosticReporter reporter, |
| 35 CompilationUnitElement element) | 35 CompilationUnitElement element) |
| 36 : super(listener, element, null); | 36 : super(reporter, element, null); |
| 37 | 37 |
| 38 void addLibraryTag(LibraryTag tag) { | 38 void addLibraryTag(LibraryTag tag) { |
| 39 pushNode(tag); | 39 pushNode(tag); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void addPartOfTag(PartOf tag) { | 42 void addPartOfTag(PartOf tag) { |
| 43 pushNode(tag); | 43 pushNode(tag); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void endClassDeclaration(int interfacesCount, Token beginToken, | 46 void endClassDeclaration(int interfacesCount, Token beginToken, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 void endYieldStatement(Token yieldToken, Token starToken, Token endToken) { | 192 void endYieldStatement(Token yieldToken, Token starToken, Token endToken) { |
| 193 Expression expression = popNode(); | 193 Expression expression = popNode(); |
| 194 pushNode(new Yield(yieldToken, starToken, expression, endToken)); | 194 pushNode(new Yield(yieldToken, starToken, expression, endToken)); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void endExpressionStatement(Token token) { | 197 void endExpressionStatement(Token token) { |
| 198 pushNode(new ExpressionStatement(popNode(), token)); | 198 pushNode(new ExpressionStatement(popNode(), token)); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void handleOnError(Token token, var errorInformation) { | 201 void handleOnError(Token token, var errorInformation) { |
| 202 listener.internalError(token, "'${token.value}': ${errorInformation}"); | 202 reporter.internalError(token, "'${token.value}': ${errorInformation}"); |
| 203 } | 203 } |
| 204 | 204 |
| 205 Token expectedFunctionBody(Token token) { | 205 Token expectedFunctionBody(Token token) { |
| 206 if (identical(token.stringValue, 'native')) { | 206 if (identical(token.stringValue, 'native')) { |
| 207 return native.handleNativeFunctionBody(this, token); | 207 return native.handleNativeFunctionBody(this, token); |
| 208 } else if (token is ErrorToken) { | 208 } else if (token is ErrorToken) { |
| 209 pushNode(null); | 209 pushNode(null); |
| 210 reportErrorToken(token); | 210 reportErrorToken(token); |
| 211 } else { | 211 } else { |
| 212 reportFatalError(token, | 212 reportFatalError(token, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 263 } |
| 264 if (argumentSend.receiver != null) internalError(node: argument); | 264 if (argumentSend.receiver != null) internalError(node: argument); |
| 265 if (argument is SendSet) internalError(node: argument); | 265 if (argument is SendSet) internalError(node: argument); |
| 266 pushNode(argument.asSend().copyWithReceiver(receiver, | 266 pushNode(argument.asSend().copyWithReceiver(receiver, |
| 267 identical(tokenString, '?.'))); | 267 identical(tokenString, '?.'))); |
| 268 } else { | 268 } else { |
| 269 NodeList arguments = new NodeList.singleton(argument); | 269 NodeList arguments = new NodeList.singleton(argument); |
| 270 pushNode(new Send(receiver, new Operator(token), arguments)); | 270 pushNode(new Send(receiver, new Operator(token), arguments)); |
| 271 } | 271 } |
| 272 if (identical(tokenString, '===')) { | 272 if (identical(tokenString, '===')) { |
| 273 listener.reportErrorMessage( | 273 reporter.reportErrorMessage( |
| 274 token, | 274 token, |
| 275 MessageKind.UNSUPPORTED_EQ_EQ_EQ, | 275 MessageKind.UNSUPPORTED_EQ_EQ_EQ, |
| 276 {'lhs': receiver, 'rhs': argument}); | 276 {'lhs': receiver, 'rhs': argument}); |
| 277 } | 277 } |
| 278 if (identical(tokenString, '!==')) { | 278 if (identical(tokenString, '!==')) { |
| 279 listener.reportErrorMessage( | 279 reporter.reportErrorMessage( |
| 280 token, | 280 token, |
| 281 MessageKind.UNSUPPORTED_BANG_EQ_EQ, | 281 MessageKind.UNSUPPORTED_BANG_EQ_EQ, |
| 282 {'lhs': receiver, 'rhs': argument}); | 282 {'lhs': receiver, 'rhs': argument}); |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 | 285 |
| 286 void beginCascade(Token token) { | 286 void beginCascade(Token token) { |
| 287 pushNode(new CascadeReceiver(popNode(), token)); | 287 pushNode(new CascadeReceiver(popNode(), token)); |
| 288 } | 288 } |
| 289 | 289 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 } | 444 } |
| 445 | 445 |
| 446 void endAwaitExpression(Token awaitToken, Token endToken) { | 446 void endAwaitExpression(Token awaitToken, Token endToken) { |
| 447 Expression expression = popNode(); | 447 Expression expression = popNode(); |
| 448 pushNode(new Await(awaitToken, expression)); | 448 pushNode(new Await(awaitToken, expression)); |
| 449 } | 449 } |
| 450 | 450 |
| 451 void endRethrowStatement(Token throwToken, Token endToken) { | 451 void endRethrowStatement(Token throwToken, Token endToken) { |
| 452 pushNode(new Rethrow(throwToken, endToken)); | 452 pushNode(new Rethrow(throwToken, endToken)); |
| 453 if (identical(throwToken.stringValue, 'throw')) { | 453 if (identical(throwToken.stringValue, 'throw')) { |
| 454 listener.reportErrorMessage( | 454 reporter.reportErrorMessage( |
| 455 throwToken, MessageKind.UNSUPPORTED_THROW_WITHOUT_EXP); | 455 throwToken, MessageKind.UNSUPPORTED_THROW_WITHOUT_EXP); |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 void handleUnaryPrefixExpression(Token token) { | 459 void handleUnaryPrefixExpression(Token token) { |
| 460 pushNode(new Send.prefix(popNode(), new Operator(token))); | 460 pushNode(new Send.prefix(popNode(), new Operator(token))); |
| 461 } | 461 } |
| 462 | 462 |
| 463 void handleSuperExpression(Token token) { | 463 void handleSuperExpression(Token token) { |
| 464 pushNode(new Identifier(token)); | 464 pushNode(new Identifier(token)); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 pushNode(new Label(name, colon)); | 807 pushNode(new Label(name, colon)); |
| 808 } | 808 } |
| 809 | 809 |
| 810 void endLabeledStatement(int labelCount) { | 810 void endLabeledStatement(int labelCount) { |
| 811 Statement statement = popNode(); | 811 Statement statement = popNode(); |
| 812 NodeList labels = makeNodeList(labelCount, null, null, null); | 812 NodeList labels = makeNodeList(labelCount, null, null, null); |
| 813 pushNode(new LabeledStatement(labels, statement)); | 813 pushNode(new LabeledStatement(labels, statement)); |
| 814 } | 814 } |
| 815 | 815 |
| 816 void log(message) { | 816 void log(message) { |
| 817 listener.log(message); | 817 reporter.log(message); |
| 818 } | 818 } |
| 819 | 819 |
| 820 void internalError({Token token, Node node}) { | 820 void internalError({Token token, Node node}) { |
| 821 // TODO(ahe): This should call listener.internalError. | 821 // TODO(ahe): This should call reporter.internalError. |
| 822 Spannable spannable = (token == null) ? node : token; | 822 Spannable spannable = (token == null) ? node : token; |
| 823 throw new SpannableAssertionFailure(spannable, 'Internal error in parser.'); | 823 throw new SpannableAssertionFailure(spannable, 'Internal error in parser.'); |
| 824 } | 824 } |
| 825 } | 825 } |
| OLD | NEW |