| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 TreeValidatorTask extends CompilerTask { | 5 class TreeValidatorTask extends CompilerTask { |
| 6 TreeValidatorTask(Compiler compiler) : super(compiler); | 6 TreeValidatorTask(Compiler compiler) : super(compiler); |
| 7 | 7 |
| 8 void validate(Node tree) { | 8 void validate(Node tree) { |
| 9 assert(check(tree)); | 9 assert(check(tree)); |
| 10 } | 10 } |
| 11 | 11 |
| 12 bool check(Node tree) { | 12 bool check(Node tree) { |
| 13 List<InvalidNodeError> errors = []; | 13 List<InvalidNodeError> errors = []; |
| 14 void report(node, message) { | 14 void report(node, message) { |
| 15 final error = new InvalidNodeError(node, message); | 15 final error = new InvalidNodeError(node, message); |
| 16 errors.add(error); | 16 errors.add(error); |
| 17 compiler.log(error); | 17 compiler.reportWarning(node, message); |
| 18 }; | 18 }; |
| 19 final validator = new ValidatorVisitor(report); | 19 final validator = new ValidatorVisitor(report); |
| 20 tree.accept(new TraversingVisitor(validator)); | 20 tree.accept(new TraversingVisitor(validator)); |
| 21 | 21 |
| 22 return errors.isEmpty(); | 22 return errors.isEmpty(); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 class ValidatorVisitor extends AbstractVisitor { | 26 class ValidatorVisitor extends AbstractVisitor { |
| 27 final Function reportInvalidNode; | 27 final Function reportInvalidNode; |
| 28 | 28 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 55 final String message; | 55 final String message; |
| 56 InvalidNodeError(this.node, [this.message]); | 56 InvalidNodeError(this.node, [this.message]); |
| 57 | 57 |
| 58 toString() { | 58 toString() { |
| 59 String nodeString = new Unparser(true).unparse(node); | 59 String nodeString = new Unparser(true).unparse(node); |
| 60 String result = 'invalid node: $nodeString'; | 60 String result = 'invalid node: $nodeString'; |
| 61 if (message !== null) result = '$result ($message)'; | 61 if (message !== null) result = '$result ($message)'; |
| 62 return result; | 62 return result; |
| 63 } | 63 } |
| 64 } | 64 } |
| OLD | NEW |