| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 return new js.Prefix("!", visitExpression(node.operand)); | 343 return new js.Prefix("!", visitExpression(node.operand)); |
| 344 } | 344 } |
| 345 | 345 |
| 346 @override | 346 @override |
| 347 js.Expression visitThis(tree_ir.This node) { | 347 js.Expression visitThis(tree_ir.This node) { |
| 348 return new js.This(); | 348 return new js.This(); |
| 349 } | 349 } |
| 350 | 350 |
| 351 @override | 351 @override |
| 352 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { | 352 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { |
| 353 js.Expression value = visitExpression(node.value); |
| 354 List<js.Expression> typeArguments = |
| 355 node.typeArguments.map(visitExpression).toList(); |
| 353 if (!node.isTypeTest) { | 356 if (!node.isTypeTest) { |
| 354 giveup(node, 'type casts not implemented.'); | 357 giveup(node, 'type casts not implemented.'); |
| 355 } | 358 } |
| 356 DartType type = node.type; | 359 DartType type = node.type; |
| 357 if (type is InterfaceType && type.isRaw) { | 360 // Note that the trivial (but special) cases of Object, dynamic, and Null |
| 361 // are handled at build-time and must not occur in a TypeOperator. |
| 362 assert(!type.isObject && !type.isDynamic); |
| 363 if (type is InterfaceType) { |
| 358 glue.registerIsCheck(type, registry); | 364 glue.registerIsCheck(type, registry); |
| 359 js.Expression value = visitExpression(node.receiver); | 365 ClassElement clazz = type.element; |
| 360 return js.js('!!#.#', [value, glue.getTypeTestTag(type)]); | 366 |
| 367 // We use the helper: |
| 368 // |
| 369 // checkSubtype(value, $isT, typeArgs, $asT) |
| 370 // |
| 371 // Any of the last two arguments may be null if there are no type |
| 372 // arguments, and/or if no substitution is required. |
| 373 |
| 374 js.Expression isT = js.string(glue.getTypeTestTag(type)); |
| 375 |
| 376 js.Expression typeArgumentArray = typeArguments.isNotEmpty |
| 377 ? new js.ArrayInitializer(typeArguments) |
| 378 : new js.LiteralNull(); |
| 379 |
| 380 js.Expression asT = glue.hasStrictSubtype(clazz) |
| 381 ? js.string(glue.getTypeSubstitutionTag(clazz)) |
| 382 : new js.LiteralNull(); |
| 383 |
| 384 return buildStaticHelperInvocation( |
| 385 glue.getCheckSubtype(), |
| 386 [value, isT, typeArgumentArray, asT]); |
| 361 } | 387 } |
| 362 return giveup(node, 'type check unimplemented for $type.'); | 388 return giveup(node, 'type check unimplemented for $type.'); |
| 363 } | 389 } |
| 364 | 390 |
| 365 @override | 391 @override |
| 366 js.Expression visitVariableUse(tree_ir.VariableUse node) { | 392 js.Expression visitVariableUse(tree_ir.VariableUse node) { |
| 367 return buildVariableAccess(node.variable); | 393 return buildVariableAccess(node.variable); |
| 368 } | 394 } |
| 369 | 395 |
| 370 js.Expression buildVariableAccess(tree_ir.Variable variable) { | 396 js.Expression buildVariableAccess(tree_ir.Variable variable) { |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 695 |
| 670 @override | 696 @override |
| 671 visitVariableDeclaration(tree_ir.VariableDeclaration node) { | 697 visitVariableDeclaration(tree_ir.VariableDeclaration node) { |
| 672 return errorUnsupportedNode(node); | 698 return errorUnsupportedNode(node); |
| 673 } | 699 } |
| 674 | 700 |
| 675 errorUnsupportedNode(tree_ir.DartSpecificNode node) { | 701 errorUnsupportedNode(tree_ir.DartSpecificNode node) { |
| 676 throw "Unsupported node in JS backend: $node"; | 702 throw "Unsupported node in JS backend: $node"; |
| 677 } | 703 } |
| 678 } | 704 } |
| OLD | NEW |