| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 new tree_ir.FallthroughStack(); | 65 new tree_ir.FallthroughStack(); |
| 66 | 66 |
| 67 Set<tree_ir.Label> usedLabels = new Set<tree_ir.Label>(); | 67 Set<tree_ir.Label> usedLabels = new Set<tree_ir.Label>(); |
| 68 | 68 |
| 69 List<js.Statement> accumulator = new List<js.Statement>(); | 69 List<js.Statement> accumulator = new List<js.Statement>(); |
| 70 | 70 |
| 71 CodeGenerator(this.glue, this.registry); | 71 CodeGenerator(this.glue, this.registry); |
| 72 | 72 |
| 73 /// Generates JavaScript code for the body of [function]. | 73 /// Generates JavaScript code for the body of [function]. |
| 74 js.Fun buildFunction(tree_ir.FunctionDefinition function) { | 74 js.Fun buildFunction(tree_ir.FunctionDefinition function) { |
| 75 registerDefaultParameterValues(function.element); |
| 75 currentFunction = function.element; | 76 currentFunction = function.element; |
| 76 visitStatement(function.body); | 77 visitStatement(function.body); |
| 77 | 78 |
| 78 List<js.Parameter> parameters = new List<js.Parameter>(); | 79 List<js.Parameter> parameters = new List<js.Parameter>(); |
| 79 Set<tree_ir.Variable> parameterSet = new Set<tree_ir.Variable>(); | 80 Set<tree_ir.Variable> parameterSet = new Set<tree_ir.Variable>(); |
| 80 Set<String> declaredVariables = new Set<String>(); | 81 Set<String> declaredVariables = new Set<String>(); |
| 81 | 82 |
| 82 for (tree_ir.Variable parameter in function.parameters) { | 83 for (tree_ir.Variable parameter in function.parameters) { |
| 83 String name = getVariableName(parameter); | 84 String name = getVariableName(parameter); |
| 84 parameters.add(new js.Parameter(name)); | 85 parameters.add(new js.Parameter(name)); |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 @override | 1011 @override |
| 1011 js.Expression visitAwait(tree_ir.Await node) { | 1012 js.Expression visitAwait(tree_ir.Await node) { |
| 1012 return new js.Await(visitExpression(node.input)); | 1013 return new js.Await(visitExpression(node.input)); |
| 1013 } | 1014 } |
| 1014 | 1015 |
| 1015 visitFunctionExpression(tree_ir.FunctionExpression node) { | 1016 visitFunctionExpression(tree_ir.FunctionExpression node) { |
| 1016 // FunctionExpressions are currently unused. | 1017 // FunctionExpressions are currently unused. |
| 1017 // We might need them if we want to emit raw JS nested functions. | 1018 // We might need them if we want to emit raw JS nested functions. |
| 1018 throw 'FunctionExpressions should not be used'; | 1019 throw 'FunctionExpressions should not be used'; |
| 1019 } | 1020 } |
| 1021 |
| 1022 /// Ensures that parameter defaults will be emitted. |
| 1023 /// |
| 1024 /// Ideally, this should be done when generating the relevant stub methods, |
| 1025 /// since those are the ones that actually reference the constants, but those |
| 1026 /// are created by the emitter when it is too late to register new constants. |
| 1027 /// |
| 1028 /// For non-static methods, we have no way of knowing if the defaults are |
| 1029 /// actually used, so we conservatively register them all. |
| 1030 void registerDefaultParameterValues(ExecutableElement element) { |
| 1031 if (element is! FunctionElement) return; |
| 1032 FunctionElement function = element; |
| 1033 if (function.isStatic) return; // Defaults are inlined at call sites. |
| 1034 function.functionSignature.forEachOptionalParameter((param) { |
| 1035 ConstantValue constant = glue.getDefaultParameterValue(param); |
| 1036 registry.registerCompileTimeConstant(constant); |
| 1037 }); |
| 1038 } |
| 1020 } | 1039 } |
| OLD | NEW |