OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
6 | 6 |
7 import '../closure.dart'; | 7 import '../closure.dart'; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../common/codegen.dart' show CodegenRegistry; | 9 import '../common/codegen.dart' show CodegenRegistry; |
10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
(...skipping 1869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 SsaBranchBuilder brancher = new SsaBranchBuilder(this); | 1880 SsaBranchBuilder brancher = new SsaBranchBuilder(this); |
1881 brancher.handleConditional( | 1881 brancher.handleConditional( |
1882 () => conditional.condition.accept(this), | 1882 () => conditional.condition.accept(this), |
1883 () => conditional.then.accept(this), | 1883 () => conditional.then.accept(this), |
1884 () => conditional.otherwise.accept(this)); | 1884 () => conditional.otherwise.accept(this)); |
1885 } | 1885 } |
1886 | 1886 |
1887 @override | 1887 @override |
1888 void visitLogicalExpression(ir.LogicalExpression logicalExpression) { | 1888 void visitLogicalExpression(ir.LogicalExpression logicalExpression) { |
1889 SsaBranchBuilder brancher = new SsaBranchBuilder(this); | 1889 SsaBranchBuilder brancher = new SsaBranchBuilder(this); |
1890 brancher.handleLogicalBinary(() => logicalExpression.left.accept(this), | 1890 String operator = logicalExpression.operator; |
1891 () => logicalExpression.right.accept(this), | 1891 // ir.LogicalExpression claims to allow '??' as an operator but currently |
1892 isAnd: logicalExpression.operator == '&&'); | 1892 // that is expanded into a let-tree. |
| 1893 assert(operator == '&&' || operator == '||'); |
| 1894 _handleLogicalExpression(logicalExpression.left, |
| 1895 () => logicalExpression.right.accept(this), brancher, operator); |
| 1896 } |
| 1897 |
| 1898 /// Optimizes logical binary expression where the left has the same logical |
| 1899 /// binary operator. |
| 1900 /// |
| 1901 /// This method transforms the operator by optimizing the case where [left] is |
| 1902 /// a logical "and" or logical "or". Then it uses [branchBuilder] to build the |
| 1903 /// graph for the optimized expression. |
| 1904 /// |
| 1905 /// For example, `(x && y) && z` is transformed into `x && (y && z)`: |
| 1906 /// |
| 1907 void _handleLogicalExpression(ir.Expression left, void visitRight(), |
| 1908 SsaBranchBuilder brancher, String operator) { |
| 1909 if (left is ir.LogicalExpression && left.operator == operator) { |
| 1910 ir.Expression innerLeft = left.left; |
| 1911 ir.Expression middle = left.right; |
| 1912 _handleLogicalExpression( |
| 1913 innerLeft, |
| 1914 () => |
| 1915 _handleLogicalExpression(middle, visitRight, brancher, operator), |
| 1916 brancher, |
| 1917 operator); |
| 1918 } else { |
| 1919 brancher.handleLogicalBinary(() => left.accept(this), visitRight, |
| 1920 isAnd: operator == '&&'); |
| 1921 } |
1893 } | 1922 } |
1894 | 1923 |
1895 @override | 1924 @override |
1896 void visitIntLiteral(ir.IntLiteral intLiteral) { | 1925 void visitIntLiteral(ir.IntLiteral intLiteral) { |
1897 stack.add(graph.addConstantInt(intLiteral.value, closedWorld)); | 1926 stack.add(graph.addConstantInt(intLiteral.value, closedWorld)); |
1898 } | 1927 } |
1899 | 1928 |
1900 @override | 1929 @override |
1901 void visitDoubleLiteral(ir.DoubleLiteral doubleLiteral) { | 1930 void visitDoubleLiteral(ir.DoubleLiteral doubleLiteral) { |
1902 stack.add(graph.addConstantDouble(doubleLiteral.value, closedWorld)); | 1931 stack.add(graph.addConstantDouble(doubleLiteral.value, closedWorld)); |
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3477 enterBlock.setBlockFlow( | 3506 enterBlock.setBlockFlow( |
3478 new HTryBlockInformation( | 3507 new HTryBlockInformation( |
3479 kernelBuilder.wrapStatementGraph(bodyGraph), | 3508 kernelBuilder.wrapStatementGraph(bodyGraph), |
3480 exception, | 3509 exception, |
3481 kernelBuilder.wrapStatementGraph(catchGraph), | 3510 kernelBuilder.wrapStatementGraph(catchGraph), |
3482 kernelBuilder.wrapStatementGraph(finallyGraph)), | 3511 kernelBuilder.wrapStatementGraph(finallyGraph)), |
3483 exitBlock); | 3512 exitBlock); |
3484 kernelBuilder.inTryStatement = previouslyInTryStatement; | 3513 kernelBuilder.inTryStatement = previouslyInTryStatement; |
3485 } | 3514 } |
3486 } | 3515 } |
OLD | NEW |