| 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 code_generator; | 5 library code_generator; |
| 6 | 6 |
| 7 import 'glue.dart'; | 7 import 'glue.dart'; |
| 8 | 8 |
| 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; | 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; |
| 10 import '../../js/js.dart' as js; | 10 import '../../js/js.dart' as js; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return arguments.map(visitExpression).toList(); | 128 return arguments.map(visitExpression).toList(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 giveup(tree_ir.Node node, | 131 giveup(tree_ir.Node node, |
| 132 [String reason = 'unimplemented in CodeGenerator']) { | 132 [String reason = 'unimplemented in CodeGenerator']) { |
| 133 throw new CodegenBailout(node, reason); | 133 throw new CodegenBailout(node, reason); |
| 134 } | 134 } |
| 135 | 135 |
| 136 @override | 136 @override |
| 137 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) { | 137 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) { |
| 138 return giveup(node); | 138 js.Expression addStrings(js.Expression left, js.Expression right) { |
| 139 // TODO: implement visitConcatenateStrings | 139 return new js.Binary('+', left, right); |
| 140 } |
| 141 |
| 142 js.Expression toString(tree_ir.Expression input) { |
| 143 bool useDirectly = input is tree_ir.Constant && |
| 144 (input.expression.value.isString || |
| 145 input.expression.value.isInt || |
| 146 input.expression.value.isBool); |
| 147 js.Expression value = visit(input); |
| 148 if (useDirectly) { |
| 149 return value; |
| 150 } else { |
| 151 Element convertToString = glue.getStringConversion(); |
| 152 registry.registerStaticUse(convertToString); |
| 153 js.Expression access = glue.staticFunctionAccess(convertToString); |
| 154 return (new js.Call(access, <js.Expression>[value])); |
| 155 } |
| 156 } |
| 157 |
| 158 return node.arguments.map(toString).reduce(addStrings); |
| 140 } | 159 } |
| 141 | 160 |
| 142 @override | 161 @override |
| 143 js.Expression visitConditional(tree_ir.Conditional node) { | 162 js.Expression visitConditional(tree_ir.Conditional node) { |
| 144 return new js.Conditional( | 163 return new js.Conditional( |
| 145 visitExpression(node.condition), | 164 visitExpression(node.condition), |
| 146 visitExpression(node.thenExpression), | 165 visitExpression(node.thenExpression), |
| 147 visitExpression(node.elseExpression)); | 166 visitExpression(node.elseExpression)); |
| 148 } | 167 } |
| 149 | 168 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 void visitSetField(tree_ir.SetField node) { | 535 void visitSetField(tree_ir.SetField node) { |
| 517 js.PropertyAccess field = | 536 js.PropertyAccess field = |
| 518 new js.PropertyAccess.field( | 537 new js.PropertyAccess.field( |
| 519 visitExpression(node.object), | 538 visitExpression(node.object), |
| 520 glue.instanceFieldPropertyName(node.field)); | 539 glue.instanceFieldPropertyName(node.field)); |
| 521 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); | 540 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); |
| 522 accumulator.add(new js.ExpressionStatement(asn)); | 541 accumulator.add(new js.ExpressionStatement(asn)); |
| 523 visitStatement(node.next); | 542 visitStatement(node.next); |
| 524 } | 543 } |
| 525 } | 544 } |
| OLD | NEW |