| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 @override | 219 @override |
| 220 js.Expression visitInvokeSuperMethod(tree_ir.InvokeSuperMethod node) { | 220 js.Expression visitInvokeSuperMethod(tree_ir.InvokeSuperMethod node) { |
| 221 return giveup(node); | 221 return giveup(node); |
| 222 // TODO: implement visitInvokeSuperMethod | 222 // TODO: implement visitInvokeSuperMethod |
| 223 } | 223 } |
| 224 | 224 |
| 225 @override | 225 @override |
| 226 js.Expression visitLiteralList(tree_ir.LiteralList node) { | 226 js.Expression visitLiteralList(tree_ir.LiteralList node) { |
| 227 registry.registerInstantiatedClass(glue.listClass); | 227 registry.registerInstantiatedClass(glue.listClass); |
| 228 int length = node.values.length; | 228 int length = node.values.length; |
| 229 List<js.ArrayElement> entries = new List<js.ArrayElement>.generate(length, | 229 List<js.Expression> entries = node.values.map(visitExpression).toList(); |
| 230 (int i) => new js.ArrayElement(i, visitExpression(node.values[i]))); | 230 return new js.ArrayInitializer(entries); |
| 231 return new js.ArrayInitializer(length, entries); | |
| 232 } | 231 } |
| 233 | 232 |
| 234 @override | 233 @override |
| 235 js.Expression visitLiteralMap(tree_ir.LiteralMap node) { | 234 js.Expression visitLiteralMap(tree_ir.LiteralMap node) { |
| 236 ConstructorElement constructor; | 235 ConstructorElement constructor; |
| 237 if (node.entries.isEmpty) { | 236 if (node.entries.isEmpty) { |
| 238 constructor = glue.mapLiteralConstructorEmpty; | 237 constructor = glue.mapLiteralConstructorEmpty; |
| 239 } else { | 238 } else { |
| 240 constructor = glue.mapLiteralConstructor; | 239 constructor = glue.mapLiteralConstructor; |
| 241 } | 240 } |
| 242 List<js.ArrayElement> entries = | 241 List<js.Expression> entries = |
| 243 new List<js.ArrayElement>(2 * node.entries.length); | 242 new List<js.Expression>(2 * node.entries.length); |
| 244 for (int i = 0; i < node.entries.length; i++) { | 243 for (int i = 0; i < node.entries.length; i++) { |
| 245 js.Expression key = visitExpression(node.entries[i].key); | 244 entries[2 * i] = visitExpression(node.entries[i].key); |
| 246 js.Expression value = visitExpression(node.entries[i].value); | 245 entries[2 * i + 1] = visitExpression(node.entries[i].value); |
| 247 entries[2 * i] = new js.ArrayElement(2 * i, key); | |
| 248 entries[2 * i + 1] = new js.ArrayElement(2 * i + 1, value); | |
| 249 } | 246 } |
| 250 List<js.Expression> args = | 247 List<js.Expression> args = |
| 251 <js.Expression>[new js.ArrayInitializer(node.entries.length * 2, | 248 <js.Expression>[new js.ArrayInitializer(entries)]; |
| 252 entries)]; | |
| 253 return buildStaticInvoke( | 249 return buildStaticInvoke( |
| 254 new Selector.call(constructor.name, constructor.library, 2), | 250 new Selector.call(constructor.name, constructor.library, 2), |
| 255 constructor, | 251 constructor, |
| 256 args); | 252 args); |
| 257 } | 253 } |
| 258 | 254 |
| 259 @override | 255 @override |
| 260 js.Expression visitLogicalOperator(tree_ir.LogicalOperator node) { | 256 js.Expression visitLogicalOperator(tree_ir.LogicalOperator node) { |
| 261 return new js.Binary(node.operator, visit(node.left), visit(node.right)); | 257 return new js.Binary(node.operator, visit(node.left), visit(node.right)); |
| 262 } | 258 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 accumulator.add( | 410 accumulator.add( |
| 415 buildWhile(new js.LiteralBool(true), node.body, node.label, node)); | 411 buildWhile(new js.LiteralBool(true), node.body, node.label, node)); |
| 416 } | 412 } |
| 417 | 413 |
| 418 @override | 414 @override |
| 419 void visitReturn(tree_ir.Return node) { | 415 void visitReturn(tree_ir.Return node) { |
| 420 accumulator.add(new js.Return(visitExpression(node.value))); | 416 accumulator.add(new js.Return(visitExpression(node.value))); |
| 421 } | 417 } |
| 422 | 418 |
| 423 } | 419 } |
| OLD | NEW |