| 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 350 |
| 354 @override | 351 @override |
| 355 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { | 352 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { |
| 356 if (!node.isTypeTest) { | 353 if (!node.isTypeTest) { |
| 357 giveup(node, 'type casts not implemented.'); | 354 giveup(node, 'type casts not implemented.'); |
| 358 } | 355 } |
| 359 DartType type = node.type; | 356 DartType type = node.type; |
| 360 if (type is InterfaceType && type.isRaw) { | 357 if (type is InterfaceType && type.isRaw) { |
| 361 glue.registerIsCheck(type, registry); | 358 glue.registerIsCheck(type, registry); |
| 362 js.Expression value = visitExpression(node.receiver); | 359 js.Expression value = visitExpression(node.receiver); |
| 363 return emitSubtypeTest(node, value, type); | 360 return js.js('!!#.#', [value, glue.getTypeTestTag(type)]); |
| 364 } | 361 } |
| 365 return giveup(node, 'type check unimplemented for $type.'); | 362 return giveup(node, 'type check unimplemented for $type.'); |
| 366 } | 363 } |
| 367 | 364 |
| 368 @override | 365 @override |
| 369 js.Expression visitVariableUse(tree_ir.VariableUse node) { | 366 js.Expression visitVariableUse(tree_ir.VariableUse node) { |
| 370 return buildVariableAccess(node.variable); | 367 return buildVariableAccess(node.variable); |
| 371 } | 368 } |
| 372 | 369 |
| 373 js.Expression buildVariableAccess(tree_ir.Variable variable) { | 370 js.Expression buildVariableAccess(tree_ir.Variable variable) { |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 669 |
| 673 @override | 670 @override |
| 674 visitVariableDeclaration(tree_ir.VariableDeclaration node) { | 671 visitVariableDeclaration(tree_ir.VariableDeclaration node) { |
| 675 return errorUnsupportedNode(node); | 672 return errorUnsupportedNode(node); |
| 676 } | 673 } |
| 677 | 674 |
| 678 errorUnsupportedNode(tree_ir.DartSpecificNode node) { | 675 errorUnsupportedNode(tree_ir.DartSpecificNode node) { |
| 679 throw "Unsupported node in JS backend: $node"; | 676 throw "Unsupported node in JS backend: $node"; |
| 680 } | 677 } |
| 681 } | 678 } |
| OLD | NEW |