| 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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 @override | 1026 @override |
| 1027 visitYield(tree_ir.Yield node) { | 1027 visitYield(tree_ir.Yield node) { |
| 1028 js.Expression value = visitExpression(node.input); | 1028 js.Expression value = visitExpression(node.input); |
| 1029 accumulator.add(new js.DartYield(value, node.hasStar)); | 1029 accumulator.add(new js.DartYield(value, node.hasStar)); |
| 1030 return node.next; | 1030 return node.next; |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 @override | 1033 @override |
| 1034 visitNullCheck(tree_ir.NullCheck node) { | 1034 visitReceiverCheck(tree_ir.ReceiverCheck node) { |
| 1035 js.Expression value = visitExpression(node.value); | 1035 js.Expression value = visitExpression(node.value); |
| 1036 // TODO(sra): Try to use the selector even when [useSelector] is false. The | 1036 // TODO(sra): Try to use the selector even when [useSelector] is false. The |
| 1037 // reason we use 'toString' is that it is always defined so avoids a slow | 1037 // reason we use 'toString' is that it is always defined so avoids a slow |
| 1038 // lookup (in V8) of an absent property. We could use the property for the | 1038 // lookup (in V8) of an absent property. We could use the property for the |
| 1039 // selector if we knew it was present. The property is present if the | 1039 // selector if we knew it was present. The property is present if the |
| 1040 // associated method was not inlined away, or if there is a noSuchMethod | 1040 // associated method was not inlined away, or if there is a noSuchMethod |
| 1041 // hook for that selector. We don't know these things here, but the decision | 1041 // hook for that selector. We don't know these things here, but the decision |
| 1042 // could be deferred by creating a deferred property that was resolved after | 1042 // could be deferred by creating a deferred property that was resolved after |
| 1043 // codegen. | 1043 // codegen. |
| 1044 js.Expression access = node.selector != null && node.useSelector | 1044 js.Expression access = node.useSelector |
| 1045 ? js.js('#.#', [value, glue.invocationName(node.selector)]) | 1045 ? js.js('#.#', [value, glue.invocationName(node.selector)]) |
| 1046 : js.js('#.toString', [value]); | 1046 : js.js('#.toString', [value]); |
| 1047 if (node.useInvoke) { |
| 1048 access = new js.Call(access, []); |
| 1049 } |
| 1047 if (node.condition != null) { | 1050 if (node.condition != null) { |
| 1048 js.Expression condition = visitExpression(node.condition); | 1051 js.Expression condition = visitExpression(node.condition); |
| 1049 js.Statement body = isNullReturn(node.next) | 1052 js.Statement body = isNullReturn(node.next) |
| 1050 ? new js.ExpressionStatement(access) | 1053 ? new js.ExpressionStatement(access) |
| 1051 : new js.Return(access); | 1054 : new js.Return(access); |
| 1052 accumulator.add(new js.If.noElse(condition, body)); | 1055 accumulator.add(new js.If.noElse(condition, body)); |
| 1053 } else { | 1056 } else { |
| 1054 accumulator.add(new js.ExpressionStatement(access)); | 1057 accumulator.add(new js.ExpressionStatement(access)); |
| 1055 } | 1058 } |
| 1056 return node.next; | 1059 return node.next; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 void registerDefaultParameterValues(ExecutableElement element) { | 1237 void registerDefaultParameterValues(ExecutableElement element) { |
| 1235 if (element is! FunctionElement) return; | 1238 if (element is! FunctionElement) return; |
| 1236 FunctionElement function = element; | 1239 FunctionElement function = element; |
| 1237 if (function.isStatic) return; // Defaults are inlined at call sites. | 1240 if (function.isStatic) return; // Defaults are inlined at call sites. |
| 1238 function.functionSignature.forEachOptionalParameter((param) { | 1241 function.functionSignature.forEachOptionalParameter((param) { |
| 1239 ConstantValue constant = glue.getDefaultParameterValue(param); | 1242 ConstantValue constant = glue.getDefaultParameterValue(param); |
| 1240 registry.registerCompileTimeConstant(constant); | 1243 registry.registerCompileTimeConstant(constant); |
| 1241 }); | 1244 }); |
| 1242 } | 1245 } |
| 1243 } | 1246 } |
| OLD | NEW |