| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library tree_ir.optimization.statement_rewriter; | 5 library tree_ir.optimization.statement_rewriter; |
| 6 | 6 |
| 7 import 'optimization.dart' show Pass; | 7 import 'optimization.dart' show Pass; |
| 8 import '../tree_ir_nodes.dart'; | 8 import '../tree_ir_nodes.dart'; |
| 9 import '../../io/source_information.dart'; | 9 import '../../io/source_information.dart'; |
| 10 import '../../elements/elements.dart'; | 10 import '../../elements/elements.dart'; |
| (...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 Statement getBranch(If node, bool polarity) { | 1139 Statement getBranch(If node, bool polarity) { |
| 1140 return polarity ? node.thenStatement : node.elseStatement; | 1140 return polarity ? node.thenStatement : node.elseStatement; |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 void handleForeignCode(ForeignCode node) { | 1143 void handleForeignCode(ForeignCode node) { |
| 1144 // Some arguments will get inserted in a JS code template. The arguments | 1144 // Some arguments will get inserted in a JS code template. The arguments |
| 1145 // will not always be evaluated (e.g. the second placeholder in the template | 1145 // will not always be evaluated (e.g. the second placeholder in the template |
| 1146 // '# && #'). | 1146 // '# && #'). |
| 1147 | 1147 bool isNullable(int position) => node.nullableArguments[position]; |
| 1148 // TODO(sra): Find out which tree_ir expressions are not nullable. It helps | |
| 1149 // a lot with templates like '#.push(#)'. | |
| 1150 bool isNullable(e) => true; | |
| 1151 | 1148 |
| 1152 int safeArguments = | 1149 int safeArguments = |
| 1153 PlaceholderSafetyAnalysis.analyze(node.codeTemplate.ast, isNullable); | 1150 PlaceholderSafetyAnalysis.analyze(node.codeTemplate.ast, isNullable); |
| 1154 inEmptyEnvironment(() { | 1151 inEmptyEnvironment(() { |
| 1155 for (int i = node.arguments.length - 1; i >= safeArguments; --i) { | 1152 for (int i = node.arguments.length - 1; i >= safeArguments; --i) { |
| 1156 node.arguments[i] = visitExpression(node.arguments[i]); | 1153 node.arguments[i] = visitExpression(node.arguments[i]); |
| 1157 } | 1154 } |
| 1158 }); | 1155 }); |
| 1159 for (int i = safeArguments - 1; i >= 0; --i) { | 1156 for (int i = safeArguments - 1; i >= 0; --i) { |
| 1160 node.arguments[i] = visitExpression(node.arguments[i]); | 1157 node.arguments[i] = visitExpression(node.arguments[i]); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 VariableUseCallback callback; | 1285 VariableUseCallback callback; |
| 1289 | 1286 |
| 1290 VariableUseVisitor(this.callback); | 1287 VariableUseVisitor(this.callback); |
| 1291 | 1288 |
| 1292 visitVariableUse(VariableUse use) => callback(use); | 1289 visitVariableUse(VariableUse use) => callback(use); |
| 1293 | 1290 |
| 1294 static void visit(Expression node, VariableUseCallback callback) { | 1291 static void visit(Expression node, VariableUseCallback callback) { |
| 1295 new VariableUseVisitor(callback).visitExpression(node); | 1292 new VariableUseVisitor(callback).visitExpression(node); |
| 1296 } | 1293 } |
| 1297 } | 1294 } |
| OLD | NEW |