| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (jsVariables.length > 0) { | 78 if (jsVariables.length > 0) { |
| 79 // Would be nice to avoid inserting at the beginning of list. | 79 // Would be nice to avoid inserting at the beginning of list. |
| 80 accumulator.insert(0, new js.ExpressionStatement( | 80 accumulator.insert(0, new js.ExpressionStatement( |
| 81 new js.VariableDeclarationList(jsVariables))); | 81 new js.VariableDeclarationList(jsVariables))); |
| 82 } | 82 } |
| 83 return new js.Fun(parameters, new js.Block(accumulator)); | 83 return new js.Fun(parameters, new js.Block(accumulator)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 js.Expression visit(tree_ir.Expression node) { | 86 @override |
| 87 js.Expression visitExpression(tree_ir.Expression node) { |
| 87 js.Expression result = node.accept(this); | 88 js.Expression result = node.accept(this); |
| 88 if (result == null) { | 89 if (result == null) { |
| 89 glue.reportInternalError('$node did not produce code.'); | 90 glue.reportInternalError('$node did not produce code.'); |
| 90 } | 91 } |
| 91 return result; | 92 return result; |
| 92 } | 93 } |
| 93 | 94 |
| 94 /// Generates a name for the given variable. First trying with the name of | 95 /// Generates a name for the given variable. First trying with the name of |
| 95 /// the [Variable.element] if it is non-null. | 96 /// the [Variable.element] if it is non-null. |
| 96 String getVariableName(tree_ir.Variable variable) { | 97 String getVariableName(tree_ir.Variable variable) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 135 |
| 135 @override | 136 @override |
| 136 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) { | 137 js.Expression visitConcatenateStrings(tree_ir.ConcatenateStrings node) { |
| 137 return giveup(node); | 138 return giveup(node); |
| 138 // TODO: implement visitConcatenateStrings | 139 // TODO: implement visitConcatenateStrings |
| 139 } | 140 } |
| 140 | 141 |
| 141 @override | 142 @override |
| 142 js.Expression visitConditional(tree_ir.Conditional node) { | 143 js.Expression visitConditional(tree_ir.Conditional node) { |
| 143 return new js.Conditional( | 144 return new js.Conditional( |
| 144 visit(node.condition), | 145 visitExpression(node.condition), |
| 145 visit(node.thenExpression), | 146 visitExpression(node.thenExpression), |
| 146 visit(node.elseExpression)); | 147 visitExpression(node.elseExpression)); |
| 147 } | 148 } |
| 148 | 149 |
| 149 js.Expression buildConstant(ConstantValue constant) { | 150 js.Expression buildConstant(ConstantValue constant) { |
| 150 registry.registerCompileTimeConstant(constant); | 151 registry.registerCompileTimeConstant(constant); |
| 151 return glue.constantReference(constant); | 152 return glue.constantReference(constant); |
| 152 } | 153 } |
| 153 | 154 |
| 154 @override | 155 @override |
| 155 js.Expression visitConstant(tree_ir.Constant node) { | 156 js.Expression visitConstant(tree_ir.Constant node) { |
| 156 return buildConstant(node.expression.value); | 157 return buildConstant(node.expression.value); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 List<js.Expression> args = | 279 List<js.Expression> args = |
| 279 <js.Expression>[new js.ArrayInitializer(entries)]; | 280 <js.Expression>[new js.ArrayInitializer(entries)]; |
| 280 return buildStaticInvoke( | 281 return buildStaticInvoke( |
| 281 new Selector.call(constructor.name, constructor.library, 2), | 282 new Selector.call(constructor.name, constructor.library, 2), |
| 282 constructor, | 283 constructor, |
| 283 args); | 284 args); |
| 284 } | 285 } |
| 285 | 286 |
| 286 @override | 287 @override |
| 287 js.Expression visitLogicalOperator(tree_ir.LogicalOperator node) { | 288 js.Expression visitLogicalOperator(tree_ir.LogicalOperator node) { |
| 288 return new js.Binary(node.operator, visit(node.left), visit(node.right)); | 289 return new js.Binary( |
| 290 node.operator, |
| 291 visitExpression(node.left), |
| 292 visitExpression(node.right)); |
| 289 } | 293 } |
| 290 | 294 |
| 291 @override | 295 @override |
| 292 js.Expression visitNot(tree_ir.Not node) { | 296 js.Expression visitNot(tree_ir.Not node) { |
| 293 return new js.Prefix("!", visitExpression(node.operand)); | 297 return new js.Prefix("!", visitExpression(node.operand)); |
| 294 } | 298 } |
| 295 | 299 |
| 296 @override | 300 @override |
| 297 js.Expression visitReifyTypeVar(tree_ir.ReifyTypeVar node) { | 301 js.Expression visitReifyTypeVar(tree_ir.ReifyTypeVar node) { |
| 298 return giveup(node); | 302 return giveup(node); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 void visitSetField(tree_ir.SetField node) { | 486 void visitSetField(tree_ir.SetField node) { |
| 483 js.PropertyAccess field = | 487 js.PropertyAccess field = |
| 484 new js.PropertyAccess.field( | 488 new js.PropertyAccess.field( |
| 485 visitExpression(node.object), | 489 visitExpression(node.object), |
| 486 glue.instanceFieldPropertyName(node.field)); | 490 glue.instanceFieldPropertyName(node.field)); |
| 487 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); | 491 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); |
| 488 accumulator.add(new js.ExpressionStatement(asn)); | 492 accumulator.add(new js.ExpressionStatement(asn)); |
| 489 visitStatement(node.next); | 493 visitStatement(node.next); |
| 490 } | 494 } |
| 491 } | 495 } |
| OLD | NEW |