| 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; |
| 11 import '../../elements/elements.dart'; | 11 import '../../elements/elements.dart'; |
| 12 import '../../io/source_information.dart' show SourceInformation; | 12 import '../../io/source_information.dart' show SourceInformation; |
| 13 import '../../util/maplet.dart'; | 13 import '../../util/maplet.dart'; |
| 14 import '../../constants/values.dart'; | 14 import '../../constants/values.dart'; |
| 15 import '../../dart2jslib.dart'; | 15 import '../../dart2jslib.dart'; |
| 16 import '../../dart_types.dart'; | 16 import '../../dart_types.dart'; |
| 17 | 17 |
| 18 part 'type_test_emitter.dart'; | |
| 19 | |
| 20 class CodegenBailout { | 18 class CodegenBailout { |
| 21 final tree_ir.Node node; | 19 final tree_ir.Node node; |
| 22 final String reason; | 20 final String reason; |
| 23 CodegenBailout(this.node, this.reason); | 21 CodegenBailout(this.node, this.reason); |
| 24 String get message { | 22 String get message { |
| 25 return 'bailout${node != null ? " on $node" : ""}: $reason'; | 23 return 'bailout${node != null ? " on $node" : ""}: $reason'; |
| 26 } | 24 } |
| 27 } | 25 } |
| 28 | 26 |
| 29 class CodeGenerator extends tree_ir.StatementVisitor | 27 class CodeGenerator extends tree_ir.StatementVisitor |
| 30 with tree_ir.ExpressionVisitor<js.Expression>, | 28 with tree_ir.ExpressionVisitor<js.Expression> { |
| 31 TypeTestEmitter { | |
| 32 final CodegenRegistry registry; | 29 final CodegenRegistry registry; |
| 33 | 30 |
| 34 final Glue glue; | 31 final Glue glue; |
| 35 | 32 |
| 36 ExecutableElement currentFunction; | 33 ExecutableElement currentFunction; |
| 37 | 34 |
| 38 /// Maps variables to their name. | 35 /// Maps variables to their name. |
| 39 Map<tree_ir.Variable, String> variableNames = <tree_ir.Variable, String>{}; | 36 Map<tree_ir.Variable, String> variableNames = <tree_ir.Variable, String>{}; |
| 40 | 37 |
| 41 /// Maps local constants to their name. | 38 /// Maps local constants to their name. |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 351 |
| 355 @override | 352 @override |
| 356 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { | 353 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { |
| 357 if (!node.isTypeTest) { | 354 if (!node.isTypeTest) { |
| 358 giveup(node, 'type casts not implemented.'); | 355 giveup(node, 'type casts not implemented.'); |
| 359 } | 356 } |
| 360 DartType type = node.type; | 357 DartType type = node.type; |
| 361 if (type is InterfaceType && type.isRaw) { | 358 if (type is InterfaceType && type.isRaw) { |
| 362 glue.registerIsCheck(type, registry); | 359 glue.registerIsCheck(type, registry); |
| 363 js.Expression value = visitExpression(node.receiver); | 360 js.Expression value = visitExpression(node.receiver); |
| 364 return emitSubtypeTest(node, value, type); | 361 return js.js('!!#.#', [value, glue.getTypeTestTag(type)]); |
| 365 } | 362 } |
| 366 return giveup(node, 'type check unimplemented for $type.'); | 363 return giveup(node, 'type check unimplemented for $type.'); |
| 367 } | 364 } |
| 368 | 365 |
| 369 @override | 366 @override |
| 370 js.Expression visitVariableUse(tree_ir.VariableUse node) { | 367 js.Expression visitVariableUse(tree_ir.VariableUse node) { |
| 371 return buildVariableAccess(node.variable); | 368 return buildVariableAccess(node.variable); |
| 372 } | 369 } |
| 373 | 370 |
| 374 js.Expression buildVariableAccess(tree_ir.Variable variable) { | 371 js.Expression buildVariableAccess(tree_ir.Variable variable) { |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 670 |
| 674 @override | 671 @override |
| 675 visitVariableDeclaration(tree_ir.VariableDeclaration node) { | 672 visitVariableDeclaration(tree_ir.VariableDeclaration node) { |
| 676 return errorUnsupportedNode(node); | 673 return errorUnsupportedNode(node); |
| 677 } | 674 } |
| 678 | 675 |
| 679 errorUnsupportedNode(tree_ir.DartSpecificNode node) { | 676 errorUnsupportedNode(tree_ir.DartSpecificNode node) { |
| 680 throw "Unsupported node in JS backend: $node"; | 677 throw "Unsupported node in JS backend: $node"; |
| 681 } | 678 } |
| 682 } | 679 } |
| OLD | NEW |