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 | 9 import '../../closure.dart' show |
10 ClosureClassElement; | 10 ClosureClassElement; |
(...skipping 11 matching lines...) Expand all Loading... |
22 BuiltinMethod, | 22 BuiltinMethod, |
23 BuiltinOperator; | 23 BuiltinOperator; |
24 import '../../types/types.dart' show | 24 import '../../types/types.dart' show |
25 TypeMask; | 25 TypeMask; |
26 import '../../universe/call_structure.dart' show | 26 import '../../universe/call_structure.dart' show |
27 CallStructure; | 27 CallStructure; |
28 import '../../universe/selector.dart' show | 28 import '../../universe/selector.dart' show |
29 Selector; | 29 Selector; |
30 import '../../universe/use.dart' show | 30 import '../../universe/use.dart' show |
31 DynamicUse, | 31 DynamicUse, |
32 StaticUse; | 32 StaticUse, |
| 33 TypeUse; |
33 import '../../util/maplet.dart'; | 34 import '../../util/maplet.dart'; |
34 | 35 |
35 class CodegenBailout { | 36 class CodegenBailout { |
36 final tree_ir.Node node; | 37 final tree_ir.Node node; |
37 final String reason; | 38 final String reason; |
38 CodegenBailout(this.node, this.reason); | 39 CodegenBailout(this.node, this.reason); |
39 String get message { | 40 String get message { |
40 return 'bailout${node != null ? " on $node" : ""}: $reason'; | 41 return 'bailout${node != null ? " on $node" : ""}: $reason'; |
41 } | 42 } |
42 } | 43 } |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 js.Expression visitThis(tree_ir.This node) { | 376 js.Expression visitThis(tree_ir.This node) { |
376 return new js.This(); | 377 return new js.This(); |
377 } | 378 } |
378 | 379 |
379 @override | 380 @override |
380 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { | 381 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { |
381 js.Expression value = visitExpression(node.value); | 382 js.Expression value = visitExpression(node.value); |
382 List<js.Expression> typeArguments = visitExpressionList(node.typeArguments); | 383 List<js.Expression> typeArguments = visitExpressionList(node.typeArguments); |
383 DartType type = node.type; | 384 DartType type = node.type; |
384 if (type is InterfaceType) { | 385 if (type is InterfaceType) { |
385 registry.registerIsCheck(type); | 386 registry.registerTypeUse(new TypeUse.isCheck(type)); |
386 //glue.registerIsCheck(type, registry); | 387 //glue.registerIsCheck(type, registry); |
387 ClassElement clazz = type.element; | 388 ClassElement clazz = type.element; |
388 | 389 |
389 if (glue.isStringClass(clazz)) { | 390 if (glue.isStringClass(clazz)) { |
390 if (node.isTypeTest) { | 391 if (node.isTypeTest) { |
391 return js.js(r'typeof # === "string"', <js.Expression>[value]); | 392 return js.js(r'typeof # === "string"', <js.Expression>[value]); |
392 } | 393 } |
393 // TODO(sra): Implement fast cast via calling 'stringTypeCast'. | 394 // TODO(sra): Implement fast cast via calling 'stringTypeCast'. |
394 } else if (glue.isBoolClass(clazz)) { | 395 } else if (glue.isBoolClass(clazz)) { |
395 if (node.isTypeTest) { | 396 if (node.isTypeTest) { |
(...skipping 25 matching lines...) Expand all Loading... |
421 : new js.LiteralNull(); | 422 : new js.LiteralNull(); |
422 | 423 |
423 js.Expression asT = glue.hasStrictSubtype(clazz) | 424 js.Expression asT = glue.hasStrictSubtype(clazz) |
424 ? js.quoteName(glue.getTypeSubstitutionTag(clazz)) | 425 ? js.quoteName(glue.getTypeSubstitutionTag(clazz)) |
425 : new js.LiteralNull(); | 426 : new js.LiteralNull(); |
426 | 427 |
427 return buildStaticHelperInvocation( | 428 return buildStaticHelperInvocation( |
428 function, | 429 function, |
429 <js.Expression>[value, isT, typeArgumentArray, asT]); | 430 <js.Expression>[value, isT, typeArgumentArray, asT]); |
430 } else if (type is TypeVariableType || type is FunctionType) { | 431 } else if (type is TypeVariableType || type is FunctionType) { |
431 registry.registerIsCheck(type); | 432 registry.registerTypeUse(new TypeUse.isCheck(type)); |
432 //glue.registerIsCheck(type, registry); | |
433 | 433 |
434 Element function = node.isTypeTest | 434 Element function = node.isTypeTest |
435 ? glue.getCheckSubtypeOfRuntimeType() | 435 ? glue.getCheckSubtypeOfRuntimeType() |
436 : glue.getSubtypeOfRuntimeTypeCast(); | 436 : glue.getSubtypeOfRuntimeTypeCast(); |
437 | 437 |
438 // The only type argument is the type held in the type variable. | 438 // The only type argument is the type held in the type variable. |
439 js.Expression typeValue = typeArguments.single; | 439 js.Expression typeValue = typeArguments.single; |
440 | 440 |
441 return buildStaticHelperInvocation( | 441 return buildStaticHelperInvocation( |
442 function, | 442 function, |
443 <js.Expression>[value, typeValue]); | 443 <js.Expression>[value, typeValue]); |
444 } | 444 } |
445 return giveup(node, 'type check unimplemented for $type.'); | 445 return giveup(node, 'type check unimplemented for $type.'); |
446 } | 446 } |
447 | 447 |
448 @override | 448 @override |
449 js.Expression visitGetTypeTestProperty(tree_ir.GetTypeTestProperty node) { | 449 js.Expression visitGetTypeTestProperty(tree_ir.GetTypeTestProperty node) { |
450 js.Expression object = visitExpression(node.object); | 450 js.Expression object = visitExpression(node.object); |
451 DartType dartType = node.dartType; | 451 DartType dartType = node.dartType; |
452 assert(dartType.isInterfaceType); | 452 assert(dartType.isInterfaceType); |
453 registry.registerIsCheck(dartType); | 453 registry.registerTypeUse(new TypeUse.isCheck(dartType)); |
454 //glue.registerIsCheck(dartType, registry); | 454 //glue.registerIsCheck(dartType, registry); |
455 js.Expression property = glue.getTypeTestTag(dartType); | 455 js.Expression property = glue.getTypeTestTag(dartType); |
456 return js.js(r'#.#', [object, property]); | 456 return js.js(r'#.#', [object, property]); |
457 } | 457 } |
458 | 458 |
459 @override | 459 @override |
460 js.Expression visitVariableUse(tree_ir.VariableUse node) { | 460 js.Expression visitVariableUse(tree_ir.VariableUse node) { |
461 return buildVariableAccess(node.variable); | 461 return buildVariableAccess(node.variable); |
462 } | 462 } |
463 | 463 |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 void registerDefaultParameterValues(ExecutableElement element) { | 1079 void registerDefaultParameterValues(ExecutableElement element) { |
1080 if (element is! FunctionElement) return; | 1080 if (element is! FunctionElement) return; |
1081 FunctionElement function = element; | 1081 FunctionElement function = element; |
1082 if (function.isStatic) return; // Defaults are inlined at call sites. | 1082 if (function.isStatic) return; // Defaults are inlined at call sites. |
1083 function.functionSignature.forEachOptionalParameter((param) { | 1083 function.functionSignature.forEachOptionalParameter((param) { |
1084 ConstantValue constant = glue.getDefaultParameterValue(param); | 1084 ConstantValue constant = glue.getDefaultParameterValue(param); |
1085 registry.registerCompileTimeConstant(constant); | 1085 registry.registerCompileTimeConstant(constant); |
1086 }); | 1086 }); |
1087 } | 1087 } |
1088 } | 1088 } |
OLD | NEW |