Chromium Code Reviews| 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); | |
|
karlklose
2015/05/27 07:38:34
Also assert(type is! InterfaceType || (type as Int
asgerf
2015/05/27 09:19:16
The assertions are mostly there to add clarity. I
| |
| 363 if (type is InterfaceType) { | |
|
karlklose
2015/05/27 07:38:35
I think we should keep the case for no type argume
asgerf
2015/05/27 09:19:16
I should have clarified in the CL description.
Th
| |
| 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 omitted 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 List<js.Expression> checkSubtypeArgs = [value, isT]; | |
| 376 | |
| 377 // If the type has type arguments, check the type arguments. | |
| 378 if (typeArguments.isNotEmpty) { | |
| 379 checkSubtypeArgs.add(new js.ArrayInitializer(typeArguments)); | |
| 380 | |
| 381 // If the type has any subclasses, the type arguments need to be | |
| 382 // computed using the $asT method. | |
| 383 if (glue.hasStrictSubtype(clazz)) { | |
| 384 js.Expression asT = js.string(glue.getTypeSubstitutionTag(clazz)); | |
| 385 checkSubtypeArgs.add(asT); | |
| 386 } | |
| 387 } | |
| 388 return buildStaticHelperInvocation( | |
| 389 glue.getCheckSubtype(), | |
| 390 checkSubtypeArgs); | |
| 361 } | 391 } |
| 362 return giveup(node, 'type check unimplemented for $type.'); | 392 return giveup(node, 'type check unimplemented for $type.'); |
| 363 } | 393 } |
| 364 | 394 |
| 365 @override | 395 @override |
| 366 js.Expression visitVariableUse(tree_ir.VariableUse node) { | 396 js.Expression visitVariableUse(tree_ir.VariableUse node) { |
| 367 return buildVariableAccess(node.variable); | 397 return buildVariableAccess(node.variable); |
| 368 } | 398 } |
| 369 | 399 |
| 370 js.Expression buildVariableAccess(tree_ir.Variable variable) { | 400 js.Expression buildVariableAccess(tree_ir.Variable variable) { |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 | 699 |
| 670 @override | 700 @override |
| 671 visitVariableDeclaration(tree_ir.VariableDeclaration node) { | 701 visitVariableDeclaration(tree_ir.VariableDeclaration node) { |
| 672 return errorUnsupportedNode(node); | 702 return errorUnsupportedNode(node); |
| 673 } | 703 } |
| 674 | 704 |
| 675 errorUnsupportedNode(tree_ir.DartSpecificNode node) { | 705 errorUnsupportedNode(tree_ir.DartSpecificNode node) { |
| 676 throw "Unsupported node in JS backend: $node"; | 706 throw "Unsupported node in JS backend: $node"; |
| 677 } | 707 } |
| 678 } | 708 } |
| OLD | NEW |