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 '../../closure.dart' show ClosureClassElement; | 9 import '../../closure.dart' show ClosureClassElement; |
| 10 import '../../common/codegen.dart' show CodegenRegistry; | 10 import '../../common/codegen.dart' show CodegenRegistry; |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { | 351 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { |
| 352 js.Expression value = visitExpression(node.value); | 352 js.Expression value = visitExpression(node.value); |
| 353 List<js.Expression> typeArguments = visitExpressionList(node.typeArguments); | 353 List<js.Expression> typeArguments = visitExpressionList(node.typeArguments); |
| 354 DartType type = node.type; | 354 DartType type = node.type; |
| 355 if (type is InterfaceType) { | 355 if (type is InterfaceType) { |
| 356 glue.registerIsCheck(type, registry); | 356 glue.registerIsCheck(type, registry); |
| 357 ClassElement clazz = type.element; | 357 ClassElement clazz = type.element; |
| 358 | 358 |
| 359 // Handle some special checks against classes that exist only in | 359 // Handle some special checks against classes that exist only in |
| 360 // the compile-time class hierarchy, not at runtime. | 360 // the compile-time class hierarchy, not at runtime. |
| 361 // TODO(sra): Is this correct? The field tests are only valid with the | |
| 362 // precondtion that [value] is an Array. They will crash on `null`. | |
|
Siggi Cherem (dart-lang)
2015/08/21 23:57:11
precondtion => precondition
sra1
2015/08/22 00:11:56
Done.
| |
| 361 if (clazz == glue.jsExtendableArrayClass) { | 363 if (clazz == glue.jsExtendableArrayClass) { |
| 364 assert(node.isTypeTest); | |
| 362 return js.js(r'!#.fixed$length', <js.Expression>[value]); | 365 return js.js(r'!#.fixed$length', <js.Expression>[value]); |
| 363 } else if (clazz == glue.jsMutableArrayClass) { | 366 } else if (clazz == glue.jsMutableArrayClass) { |
| 367 assert(node.isTypeTest); | |
| 364 return js.js(r'!#.immutable$list', <js.Expression>[value]); | 368 return js.js(r'!#.immutable$list', <js.Expression>[value]); |
| 365 } | 369 } |
| 366 | 370 |
| 371 if (glue.isStringClass(clazz)) { | |
| 372 if (node.isTypeTest) { | |
| 373 return js.js(r'typeof # === "string"', <js.Expression>[value]); | |
| 374 } | |
| 375 // TODO(sra): Implement fast cast via calling 'stringTypeCast'. | |
| 376 } else if (glue.isBoolClass(clazz)) { | |
| 377 if (node.isTypeTest) { | |
| 378 return js.js(r'typeof # === "boolean"', <js.Expression>[value]); | |
| 379 } | |
| 380 // TODO(sra): Implement fast cast via calling 'boolTypeCast'. | |
| 381 } | |
| 382 | |
| 367 // The helper we use needs the JSArray class to exist, but for some | 383 // The helper we use needs the JSArray class to exist, but for some |
| 368 // reason the helper does not cause this dependency to be registered. | 384 // reason the helper does not cause this dependency to be registered. |
| 369 // TODO(asgerf): Most programs need List anyway, but we should fix this. | 385 // TODO(asgerf): Most programs need List anyway, but we should fix this. |
| 370 registry.registerInstantiatedClass(glue.listClass); | 386 registry.registerInstantiatedClass(glue.listClass); |
| 371 | 387 |
| 372 // We use one of the two helpers: | 388 // We use one of the two helpers: |
| 373 // | 389 // |
| 374 // checkSubtype(value, $isT, typeArgs, $asT) | 390 // checkSubtype(value, $isT, typeArgs, $asT) |
| 375 // subtypeCast(value, $isT, typeArgs, $asT) | 391 // subtypeCast(value, $isT, typeArgs, $asT) |
| 376 // | 392 // |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 js.Expression visitAwait(tree_ir.Await node) { | 908 js.Expression visitAwait(tree_ir.Await node) { |
| 893 return new js.Await(visitExpression(node.input)); | 909 return new js.Await(visitExpression(node.input)); |
| 894 } | 910 } |
| 895 | 911 |
| 896 visitFunctionExpression(tree_ir.FunctionExpression node) { | 912 visitFunctionExpression(tree_ir.FunctionExpression node) { |
| 897 // FunctionExpressions are currently unused. | 913 // FunctionExpressions are currently unused. |
| 898 // We might need them if we want to emit raw JS nested functions. | 914 // We might need them if we want to emit raw JS nested functions. |
| 899 throw 'FunctionExpressions should not be used'; | 915 throw 'FunctionExpressions should not be used'; |
| 900 } | 916 } |
| 901 } | 917 } |
| OLD | NEW |