Chromium Code Reviews| 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 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 Loading... | |
| 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 08:10:37
rewriteTo?
"rewriteTo" is a weird name. What does
Anton Muhin
2012/09/21 12:02:14
Any better proposals?
| |
| 86 if (statement is Block) { | |
| 87 Link statements = statement.statements.nodes; | |
| 88 if (!statements.isEmpty() && statements.tail.isEmpty()) { | |
| 89 Statement single = statements.head; | |
| 90 if (single is !VariableDefinitions) return single; | |
|
Roman
2012/09/21 08:10:37
What about function declarations?
main() {
f(){
Anton Muhin
2012/09/21 12:02:14
Well spotted, thanks a lot!
On 2012/09/21 08:10:3
| |
| 91 } | |
| 92 } | |
| 93 return statement; | |
| 94 } | |
| 95 | |
| 85 rewriteBody(Statement body) { | 96 rewriteBody(Statement body) { |
| 86 if (body is !Block) return visit(body); | 97 if (body is !Block) return visit(body); |
| 87 Block block = body; | 98 Block block = body; |
| 88 NodeList statements = block.statements; | 99 NodeList statements = block.statements; |
| 89 LinkBuilder<Statement> builder = new LinkBuilder<Statement>(); | 100 LinkBuilder<Statement> builder = new LinkBuilder<Statement>(); |
| 90 for (Statement statement in statements.nodes) { | 101 for (Statement statement in statements.nodes) { |
| 91 if (!shouldOmit(statement)) builder.addLast(visit(statement)); | 102 if (!shouldOmit(statement)) { |
| 103 builder.addLast(visit(rewritTo(statement))); | |
| 104 } | |
| 92 } | 105 } |
| 93 return new Block(rewriteNodeList(statements, builder.toLink())); | 106 return new Block(rewriteNodeList(statements, builder.toLink())); |
| 94 } | 107 } |
| 95 | 108 |
| 96 return rewriteFunctionExpression(node, rewriteBody(node.body)); | 109 return rewriteFunctionExpression(node, rewriteBody(node.body)); |
| 97 } | 110 } |
| 98 } | 111 } |
| 99 | 112 |
| 100 class DartBackend extends Backend { | 113 class DartBackend extends Backend { |
| 101 final List<CompilerTask> tasks; | 114 final List<CompilerTask> tasks; |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 } | 446 } |
| 434 | 447 |
| 435 compareElements(e0, e1) { | 448 compareElements(e0, e1) { |
| 436 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); | 449 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); |
| 437 if (result != 0) return result; | 450 if (result != 0) return result; |
| 438 return compareBy((e) => e.position().charOffset)(e0, e1); | 451 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 439 } | 452 } |
| 440 | 453 |
| 441 List<Element> sortElements(Collection<Element> elements) => | 454 List<Element> sortElements(Collection<Element> elements) => |
| 442 sorted(elements, compareElements); | 455 sorted(elements, compareElements); |
| OLD | NEW |