| 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 class ValidatorListener implements DiagnosticListener { | 5 class ValidatorListener implements DiagnosticListener { |
| 6 final SourceFile sourceFile; | 6 final SourceFile sourceFile; |
| 7 | 7 |
| 8 ValidatorListener(this.sourceFile); | 8 ValidatorListener(this.sourceFile); |
| 9 | 9 |
| 10 void cancel([String reason, node, token, instruction, element]) { | 10 void cancel([String reason, node, token, instruction, element]) { |
| 11 assert(token !== null); | 11 assert(token !== null); |
| 12 SourceSpan.withOffsets(token, token, (beginOffset, endOffset) { | 12 SourceSpan.withOffsets(token, token, (beginOffset, endOffset) { |
| 13 String errorMessage = | 13 String errorMessage = |
| 14 sourceFile.getLocationMessage(reason, beginOffset, endOffset, true); | 14 sourceFile.getLocationMessage(reason, beginOffset, endOffset, true); |
| 15 print(errorMessage); | 15 print(errorMessage); |
| 16 }); | 16 }); |
| 17 throw new CompilerCancelledException(reason); | 17 throw new CompilerCancelledException(reason); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void log(message) {} | 20 void log(message) {} |
| 21 } | 21 } |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Checks result's of [Node] unparse. | 24 * Checks result's of [Node] unparse. |
| 25 */ | 25 */ |
| 26 class UnparseValidator extends CompilerTask { | 26 class UnparseValidator extends CompilerTask { |
| 27 final bool validateUnparse; | 27 final bool validateUnparse; |
| 28 | 28 |
| 29 String get name() => "Unparse validator"; |
| 30 |
| 29 UnparseValidator(Compiler compiler, this.validateUnparse) : super(compiler); | 31 UnparseValidator(Compiler compiler, this.validateUnparse) : super(compiler); |
| 30 | 32 |
| 31 void check(Element element) { | 33 void check(Element element) { |
| 32 if (!validateUnparse) return; | 34 if (!validateUnparse) return; |
| 33 | 35 |
| 34 // TODO(antonm): consider supporting other kinds of elements. | 36 // TODO(antonm): consider supporting other kinds of elements. |
| 35 if (element is! PartialFunctionElement) return; | 37 if (element is! PartialFunctionElement) return; |
| 36 | 38 |
| 37 PartialFunctionElement originalFunction = element; | 39 PartialFunctionElement originalFunction = element; |
| 38 FunctionExpression originalNode = originalFunction.parseNode(compiler); | 40 FunctionExpression originalNode = originalFunction.parseNode(compiler); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 new Script(originalScript.uri, synthesizedSourceFile); | 59 new Script(originalScript.uri, synthesizedSourceFile); |
| 58 LibraryElement lib = new LibraryElement(synthesizedScript); | 60 LibraryElement lib = new LibraryElement(synthesizedScript); |
| 59 NodeListener listener = | 61 NodeListener listener = |
| 60 new NodeListener(new ValidatorListener(synthesizedSourceFile), lib); | 62 new NodeListener(new ValidatorListener(synthesizedSourceFile), lib); |
| 61 parser = new Parser(listener); | 63 parser = new Parser(listener); |
| 62 parser.parseFunction(newTokens, getOrSet); | 64 parser.parseFunction(newTokens, getOrSet); |
| 63 FunctionExpression newNode = listener.popNode(); | 65 FunctionExpression newNode = listener.popNode(); |
| 64 // TODO(antonm): add Node comparison. | 66 // TODO(antonm): add Node comparison. |
| 65 } | 67 } |
| 66 } | 68 } |
| OLD | NEW |