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(); | |
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 // Note that the trivial (but special) cases of Object, dynamic, and Null | 357 if (type is InterfaceType && type.isRaw) { |
361 // are handled at build-time and must not occur in a TypeOperator. | |
362 assert(!type.isObject && !type.isDynamic); | |
363 if (type is InterfaceType) { | |
364 glue.registerIsCheck(type, registry); | 358 glue.registerIsCheck(type, registry); |
365 ClassElement clazz = type.element; | 359 js.Expression value = visitExpression(node.receiver); |
366 | 360 return js.js('!!#.#', [value, glue.getTypeTestTag(type)]); |
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]); | |
387 } | 361 } |
388 return giveup(node, 'type check unimplemented for $type.'); | 362 return giveup(node, 'type check unimplemented for $type.'); |
389 } | 363 } |
390 | 364 |
391 @override | 365 @override |
392 js.Expression visitVariableUse(tree_ir.VariableUse node) { | 366 js.Expression visitVariableUse(tree_ir.VariableUse node) { |
393 return buildVariableAccess(node.variable); | 367 return buildVariableAccess(node.variable); |
394 } | 368 } |
395 | 369 |
396 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... |
695 | 669 |
696 @override | 670 @override |
697 visitVariableDeclaration(tree_ir.VariableDeclaration node) { | 671 visitVariableDeclaration(tree_ir.VariableDeclaration node) { |
698 return errorUnsupportedNode(node); | 672 return errorUnsupportedNode(node); |
699 } | 673 } |
700 | 674 |
701 errorUnsupportedNode(tree_ir.DartSpecificNode node) { | 675 errorUnsupportedNode(tree_ir.DartSpecificNode node) { |
702 throw "Unsupported node in JS backend: $node"; | 676 throw "Unsupported node in JS backend: $node"; |
703 } | 677 } |
704 } | 678 } |
OLD | NEW |