| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Checks result's of [Node] unparse. |
| 7 */ |
| 8 class UnparseValidator extends CompilerTask { |
| 9 final bool validateUnparse; |
| 10 |
| 11 UnparseValidator(Compiler compiler, this.validateUnparse) : super(compiler); |
| 12 |
| 13 void check(Element element) { |
| 14 if (!validateUnparse) return; |
| 15 |
| 16 // TODO(antonm): consider supporting other kinds of elements. |
| 17 if (element is! PartialFunctionElement) return; |
| 18 |
| 19 PartialFunctionElement originalFunction = element; |
| 20 FunctionExpression originalNode = originalFunction.parseNode(compiler); |
| 21 String unparsed = originalNode.unparse(false); |
| 22 |
| 23 Token newTokens = new StringScanner(unparsed).tokenize(); |
| 24 |
| 25 // Find the getOrSet token. |
| 26 // TODO(ahe): This is to frigging complicated. Simplify it. |
| 27 Parser parser = new Parser(new Listener()); |
| 28 Token getOrSet = |
| 29 parser.findGetOrSet(parser.parseModifiers(newTokens)); |
| 30 |
| 31 // TODO(ahe): This is also too frigging complicated. |
| 32 Script originalScript = element.getCompilationUnit().script; |
| 33 SourceFile synthesizedSourceFile = |
| 34 new SourceFile(originalScript.name, unparsed); |
| 35 Script synthesizedScript = |
| 36 new Script(originalScript.uri, synthesizedSourceFile); |
| 37 LibraryElement lib = new LibraryElement(synthesizedScript); |
| 38 NodeListener listener = new NodeListener(compiler, lib); |
| 39 parser = new Parser(listener); |
| 40 // TODO(antonm): better error reporting. |
| 41 compiler.withCurrentElement(lib, () { |
| 42 parser.parseFunction(newTokens, getOrSet); |
| 43 }); |
| 44 FunctionExpression newNode = listener.popNode(); |
| 45 // TODO(antonm): add Node comparison. |
| 46 } |
| 47 } |
| OLD | NEW |