Chromium Code Reviews| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 return arguments.map(visitExpression).toList(); | 127 return arguments.map(visitExpression).toList(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 giveup(tree_ir.Node node, | 130 giveup(tree_ir.Node node, |
| 131 [String reason = 'unimplemented in CodeGenerator']) { | 131 [String reason = 'unimplemented in CodeGenerator']) { |
| 132 throw new CodegenBailout(node, reason); | 132 throw new CodegenBailout(node, reason); |
| 133 } | 133 } |
| 134 | 134 |
| 135 @override | 135 @override |
| 136 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) { | 136 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) { |
| 137 return giveup(node); | 137 js.Expression addStrings(js.Expression left, js.Expression right) { |
| 138 // TODO: implement visitConcatenateStrings | 138 return new js.Binary('+', left, right); |
| 139 } | |
| 140 | |
| 141 js.Expression toString(tree_ir.Expression input) { | |
| 142 bool useDirectly = input is tree_ir.Constant && | |
| 143 (input.expression.value.isString || | |
| 144 input.expression.value.isInt || | |
| 145 input.expression.value.isBool); | |
| 146 js.Expression value = visit(input); | |
| 147 if (useDirectly) { | |
| 148 return value; | |
| 149 } else { | |
| 150 Element convertToString = glue.getStringConversion(); | |
| 151 registry.registerStaticUse(convertToString); | |
| 152 js.Expression access = glue.staticFunctionAccess(convertToString); | |
| 153 return (new js.Call(access, <js.Expression>[value])); | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 Iterable<js.Expression> parts = node.arguments.map(toString); | |
| 158 return parts.skip(1).fold(parts.first, addStrings); | |
|
asgerf
2015/02/06 10:37:25
Could be: parts.reduce(addStrings)
| |
| 139 } | 159 } |
| 140 | 160 |
| 141 @override | 161 @override |
| 142 js.Expression visitConditional(tree_ir.Conditional node) { | 162 js.Expression visitConditional(tree_ir.Conditional node) { |
| 143 return new js.Conditional( | 163 return new js.Conditional( |
| 144 visit(node.condition), | 164 visit(node.condition), |
| 145 visit(node.thenExpression), | 165 visit(node.thenExpression), |
| 146 visit(node.elseExpression)); | 166 visit(node.elseExpression)); |
| 147 } | 167 } |
| 148 | 168 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 void visitSetField(tree_ir.SetField node) { | 481 void visitSetField(tree_ir.SetField node) { |
| 462 js.PropertyAccess field = | 482 js.PropertyAccess field = |
| 463 new js.PropertyAccess.field( | 483 new js.PropertyAccess.field( |
| 464 visitExpression(node.object), | 484 visitExpression(node.object), |
| 465 glue.instanceFieldPropertyName(node.field)); | 485 glue.instanceFieldPropertyName(node.field)); |
| 466 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); | 486 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); |
| 467 accumulator.add(new js.ExpressionStatement(asn)); | 487 accumulator.add(new js.ExpressionStatement(asn)); |
| 468 visitStatement(node.next); | 488 visitStatement(node.next); |
| 469 } | 489 } |
| 470 } | 490 } |
| OLD | NEW |