Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: lib/compiler/implementation/unparse_validator.dart

Issue 10632019: Place more guards for the cases which should be covered. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 /** 24 /**
25 * Checks result's of [Node] unparse. 25 * Checks result's of [Node] unparse.
26 */ 26 */
27 class UnparseValidator extends CompilerTask { 27 class UnparseValidator extends CompilerTask {
28 final bool validateUnparse; 28 final bool validateUnparse;
29 29
30 String get name() => "Unparse validator"; 30 String get name() => "Unparse validator";
31 31
32 UnparseValidator(Compiler compiler, this.validateUnparse) : super(compiler); 32 UnparseValidator(Compiler compiler, this.validateUnparse) : super(compiler);
33 33
34 void check(Element element) { 34 void checkFunction(PartialFunctionElement originalFunction) {
35 if (!validateUnparse) return;
36
37 // TODO(antonm): consider supporting other kinds of elements.
38 if (element is! PartialFunctionElement) return;
39
40 PartialFunctionElement originalFunction = element;
41 FunctionExpression originalNode = originalFunction.parseNode(compiler); 35 FunctionExpression originalNode = originalFunction.parseNode(compiler);
42 String unparsed = originalNode.unparse(); 36 String unparsed = originalNode.unparse();
43 37
44 Token newTokens = new StringScanner(unparsed).tokenize(); 38 Token newTokens = new StringScanner(unparsed).tokenize();
45 39
46 // Find the getOrSet token. 40 // Find the getOrSet token.
47 // TODO(ahe): This is to frigging complicated. Simplify it. 41 // TODO(ahe): This is to frigging complicated. Simplify it.
48 Parser parser = new Parser(new Listener()); 42 Parser parser = new Parser(new Listener());
49 Token getOrSet = 43 Token getOrSet =
50 parser.findGetOrSet(parser.parseModifiers(newTokens)); 44 parser.findGetOrSet(parser.parseModifiers(newTokens));
51 45
52 // TODO(ahe): This is also too frigging complicated. 46 // TODO(ahe): This is also too frigging complicated.
53 Script originalScript = element.getCompilationUnit().script; 47 Script originalScript = originalFunction.getCompilationUnit().script;
54 String name = SourceSpan.withOffsets( 48 String name = SourceSpan.withOffsets(
55 originalFunction.beginToken, originalFunction.endToken, 49 originalFunction.beginToken, originalFunction.endToken,
56 (beginOffset, endOffset) => 50 (beginOffset, endOffset) =>
57 'synthesized:${originalScript.name}#$beginOffset:$endOffset'); 51 'synthesized:${originalScript.name}#$beginOffset:$endOffset');
58 SourceFile synthesizedSourceFile = new SourceFile(name, unparsed); 52 SourceFile synthesizedSourceFile = new SourceFile(name, unparsed);
59 Script synthesizedScript = 53 Script synthesizedScript =
60 new Script(originalScript.uri, synthesizedSourceFile); 54 new Script(originalScript.uri, synthesizedSourceFile);
61 LibraryElement lib = new LibraryElement(synthesizedScript); 55 LibraryElement lib = new LibraryElement(synthesizedScript);
62 lib.canUseNative = element.getLibrary().canUseNative; 56 lib.canUseNative = originalFunction.getLibrary().canUseNative;
63 NodeListener listener = 57 NodeListener listener =
64 new NodeListener(new ValidatorListener(synthesizedSourceFile), lib); 58 new NodeListener(new ValidatorListener(synthesizedSourceFile), lib);
65 parser = new Parser(listener); 59 parser = new Parser(listener);
66 parser.parseFunction(newTokens, getOrSet); 60 parser.parseFunction(newTokens, getOrSet);
67 FunctionExpression newNode = listener.popNode(); 61 FunctionExpression newNode = listener.popNode();
68 // TODO(antonm): add Node comparison. 62 // TODO(antonm): add Node comparison.
69 } 63 }
64
65 void check(Element element) {
66 if (!validateUnparse) return;
67
68 if (element is PartialFunctionElement) {
69 checkFunction(element);
70 } else if (element.isGenerativeConstructor()) {
71 assert(element is FunctionElement);
72 // Generative constructors parse to very special function expressions.
73 // Handle them when classes are properly handled.
74 } else if (element.isField()) {
75 assert(element is VariableElement);
76 // Fields are just names with possible initialization expressions.
77 // Nothing to care about for now.
78 } else {
79 compiler.cancel('Cannot handle $element', element: element);
80 }
81 }
70 } 82 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698