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

Side by Side Diff: lib/compiler/implementation/dart_backend/backend.dart

Issue 10962015: Rewrite blocks of single operator into just a single operator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 const bool REMOVE_ASSERTS = false; 5 const bool REMOVE_ASSERTS = false;
6 6
7 class ElementAst { 7 class ElementAst {
8 final Node ast; 8 final Node ast;
9 final TreeElements treeElements; 9 final TreeElements treeElements;
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (send !== null) { 75 if (send !== null) {
76 Element element = originalTreeElements[send]; 76 Element element = originalTreeElements[send];
77 if (REMOVE_ASSERTS && element === compiler.assertMethod) { 77 if (REMOVE_ASSERTS && element === compiler.assertMethod) {
78 return true; 78 return true;
79 } 79 }
80 } 80 }
81 } 81 }
82 return false; 82 return false;
83 } 83 }
84 84
85 rewritTo(Statement statement) {
Roman 2012/09/21 12:10:27 tryRewriteSingleStatementBlock?
Anton Muhin 2012/09/21 12:13:08 There should be no references to single statement
Roman 2012/09/21 12:16:00 then just rewriteStatement? side note: does 'try'
86 if (statement is Block) {
87 Link statements = statement.statements.nodes;
88 if (!statements.isEmpty() && statements.tail.isEmpty()) {
89 Statement single = statements.head;
90 bool isDeclaration =
91 single is VariableDefinitions || single is FunctionDeclaration;
92 if (!isDeclaration) return single;
93 }
94 }
95 return statement;
96 }
97
85 rewriteBody(Statement body) { 98 rewriteBody(Statement body) {
86 if (body is !Block) return visit(body); 99 if (body is !Block) return visit(body);
87 Block block = body; 100 Block block = body;
88 NodeList statements = block.statements; 101 NodeList statements = block.statements;
89 LinkBuilder<Statement> builder = new LinkBuilder<Statement>(); 102 LinkBuilder<Statement> builder = new LinkBuilder<Statement>();
90 for (Statement statement in statements.nodes) { 103 for (Statement statement in statements.nodes) {
91 if (!shouldOmit(statement)) builder.addLast(visit(statement)); 104 if (!shouldOmit(statement)) {
105 builder.addLast(visit(rewritTo(statement)));
106 }
92 } 107 }
93 return new Block(rewriteNodeList(statements, builder.toLink())); 108 return new Block(rewriteNodeList(statements, builder.toLink()));
94 } 109 }
95 110
96 return rewriteFunctionExpression(node, rewriteBody(node.body)); 111 return rewriteFunctionExpression(node, rewriteBody(node.body));
97 } 112 }
98 } 113 }
99 114
100 class DartBackend extends Backend { 115 class DartBackend extends Backend {
101 final List<CompilerTask> tasks; 116 final List<CompilerTask> tasks;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 448 }
434 449
435 compareElements(e0, e1) { 450 compareElements(e0, e1) {
436 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); 451 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1);
437 if (result != 0) return result; 452 if (result != 0) return result;
438 return compareBy((e) => e.position().charOffset)(e0, e1); 453 return compareBy((e) => e.position().charOffset)(e0, e1);
439 } 454 }
440 455
441 List<Element> sortElements(Collection<Element> elements) => 456 List<Element> sortElements(Collection<Element> elements) =>
442 sorted(elements, compareElements); 457 sorted(elements, compareElements);
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