| 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]) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 String name = SourceSpan.withCharacterOffsets( | 48 String name = SourceSpan.withCharacterOffsets( |
| 49 originalFunction.beginToken, originalFunction.endToken, | 49 originalFunction.beginToken, originalFunction.endToken, |
| 50 (beginOffset, endOffset) => | 50 (beginOffset, endOffset) => |
| 51 'synthesized:${originalScript.name}#$beginOffset:$endOffset'); | 51 'synthesized:${originalScript.name}#$beginOffset:$endOffset'); |
| 52 SourceFile synthesizedSourceFile = new SourceFile(name, unparsed); | 52 SourceFile synthesizedSourceFile = new SourceFile(name, unparsed); |
| 53 Script synthesizedScript = | 53 Script synthesizedScript = |
| 54 new Script(originalScript.uri, synthesizedSourceFile); | 54 new Script(originalScript.uri, synthesizedSourceFile); |
| 55 LibraryElement lib = new LibraryElement(synthesizedScript); | 55 LibraryElement lib = new LibraryElement(synthesizedScript); |
| 56 lib.canUseNative = originalFunction.getLibrary().canUseNative; | 56 lib.canUseNative = originalFunction.getLibrary().canUseNative; |
| 57 NodeListener listener = | 57 NodeListener listener = |
| 58 new NodeListener(new ValidatorListener(synthesizedSourceFile), lib); | 58 new NodeListener(new ValidatorListener(synthesizedSourceFile), |
| 59 lib.entryCompilationUnit); |
| 59 parser = new Parser(listener); | 60 parser = new Parser(listener); |
| 60 parser.parseFunction(newTokens, getOrSet); | 61 parser.parseFunction(newTokens, getOrSet); |
| 61 FunctionExpression newNode = listener.popNode(); | 62 FunctionExpression newNode = listener.popNode(); |
| 62 // TODO(antonm): add Node comparison. | 63 // TODO(antonm): add Node comparison. |
| 63 } | 64 } |
| 64 | 65 |
| 65 void check(Element element) { | 66 void check(Element element) { |
| 66 if (!validateUnparse) return; | 67 if (!validateUnparse) return; |
| 67 | 68 |
| 68 if (element is PartialFunctionElement) { | 69 if (element is PartialFunctionElement) { |
| 69 checkFunction(element); | 70 checkFunction(element); |
| 70 } else if (element.isGenerativeConstructor()) { | 71 } else if (element.isGenerativeConstructor()) { |
| 71 assert(element is FunctionElement); | 72 assert(element is FunctionElement); |
| 72 // Generative constructors parse to very special function expressions. | 73 // Generative constructors parse to very special function expressions. |
| 73 // Handle them when classes are properly handled. | 74 // Handle them when classes are properly handled. |
| 74 } else if (element.isField() || element is AbstractFieldElement) { | 75 } else if (element.isField() || element is AbstractFieldElement) { |
| 75 assert(element is VariableElement || element is AbstractFieldElement); | 76 assert(element is VariableElement || element is AbstractFieldElement); |
| 76 // Fields are just names with possible initialization expressions. | 77 // Fields are just names with possible initialization expressions. |
| 77 // Nothing to care about for now. | 78 // Nothing to care about for now. |
| 78 } else if (element is VoidElement) { | 79 } else if (element is VoidElement) { |
| 79 // Nothing to do here. | 80 // Nothing to do here. |
| 80 } else { | 81 } else { |
| 81 compiler.cancel('Cannot handle $element'); | 82 compiler.cancel('Cannot handle $element'); |
| 82 } | 83 } |
| 83 } | 84 } |
| 84 } | 85 } |
| OLD | NEW |