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 dart2js.js_emitter.program_builder; | 5 library dart2js.js_emitter.program_builder; |
6 | 6 |
7 import 'js_emitter.dart' show computeMixinClass; | 7 import 'js_emitter.dart' show computeMixinClass; |
8 import 'model.dart'; | 8 import 'model.dart'; |
9 | 9 |
10 import '../common.dart'; | 10 import '../common.dart'; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 _task.outputStaticNonFinalFieldLists[librariesMap.outputUnit]; | 203 _task.outputStaticNonFinalFieldLists[librariesMap.outputUnit]; |
204 if (staticNonFinalFields == null) return const <StaticField>[]; | 204 if (staticNonFinalFields == null) return const <StaticField>[]; |
205 | 205 |
206 return staticNonFinalFields | 206 return staticNonFinalFields |
207 .map(_buildStaticField) | 207 .map(_buildStaticField) |
208 .toList(growable: false); | 208 .toList(growable: false); |
209 } | 209 } |
210 | 210 |
211 StaticField _buildStaticField(Element element) { | 211 StaticField _buildStaticField(Element element) { |
212 JavaScriptConstantCompiler handler = backend.constants; | 212 JavaScriptConstantCompiler handler = backend.constants; |
213 ConstantValue initialValue = handler.getInitialValueFor(element).value; | 213 ConstantValue initialValue = handler.getInitialValueFor(element); |
214 // TODO(zarah): The holder should not be registered during building of | 214 // TODO(zarah): The holder should not be registered during building of |
215 // a static field. | 215 // a static field. |
216 _registry.registerHolder(namer.globalObjectForConstant(initialValue)); | 216 _registry.registerHolder(namer.globalObjectForConstant(initialValue)); |
217 js.Expression code = _task.emitter.constantReference(initialValue); | 217 js.Expression code = _task.emitter.constantReference(initialValue); |
218 String name = namer.globalPropertyName(element); | 218 String name = namer.globalPropertyName(element); |
219 bool isFinal = false; | 219 bool isFinal = false; |
220 bool isLazy = false; | 220 bool isLazy = false; |
221 | 221 |
222 // TODO(floitsch): we shouldn't update the registry in the middle of | 222 // TODO(floitsch): we shouldn't update the registry in the middle of |
223 // building a static field. (Note that the $ holder is already registered | 223 // building a static field. (Note that the $ holder is already registered |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 } else { | 459 } else { |
460 return _buildStaticMethod(element); | 460 return _buildStaticMethod(element); |
461 } | 461 } |
462 } | 462 } |
463 | 463 |
464 /* Map | List */ _computeParameterDefaultValues(FunctionSignature signature) { | 464 /* Map | List */ _computeParameterDefaultValues(FunctionSignature signature) { |
465 var /* Map | List */ optionalParameterDefaultValues; | 465 var /* Map | List */ optionalParameterDefaultValues; |
466 if (signature.optionalParametersAreNamed) { | 466 if (signature.optionalParametersAreNamed) { |
467 optionalParameterDefaultValues = new Map<String, ConstantValue>(); | 467 optionalParameterDefaultValues = new Map<String, ConstantValue>(); |
468 signature.forEachOptionalParameter((ParameterElement parameter) { | 468 signature.forEachOptionalParameter((ParameterElement parameter) { |
469 ConstantExpression def = | 469 ConstantValue def = |
470 backend.constants.getConstantForVariable(parameter); | 470 backend.constants.getConstantValueForVariable(parameter); |
471 optionalParameterDefaultValues[parameter.name] = def.value; | 471 optionalParameterDefaultValues[parameter.name] = def; |
472 }); | 472 }); |
473 } else { | 473 } else { |
474 optionalParameterDefaultValues = <ConstantValue>[]; | 474 optionalParameterDefaultValues = <ConstantValue>[]; |
475 signature.forEachOptionalParameter((ParameterElement parameter) { | 475 signature.forEachOptionalParameter((ParameterElement parameter) { |
476 ConstantExpression def = | 476 ConstantValue def = |
477 backend.constants.getConstantForVariable(parameter); | 477 backend.constants.getConstantValueForVariable(parameter); |
478 optionalParameterDefaultValues.add(def.value); | 478 optionalParameterDefaultValues.add(def); |
479 }); | 479 }); |
480 } | 480 } |
481 return optionalParameterDefaultValues; | 481 return optionalParameterDefaultValues; |
482 } | 482 } |
483 | 483 |
484 DartMethod _buildMethod(MethodElement element) { | 484 DartMethod _buildMethod(MethodElement element) { |
485 String name = namer.methodPropertyName(element); | 485 String name = namer.methodPropertyName(element); |
486 js.Expression code = backend.generatedCode[element]; | 486 js.Expression code = backend.generatedCode[element]; |
487 | 487 |
488 // TODO(kasperl): Figure out under which conditions code is null. | 488 // TODO(kasperl): Figure out under which conditions code is null. |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 _registry.registerConstant(outputUnit, constantValue); | 755 _registry.registerConstant(outputUnit, constantValue); |
756 assert(!_constants.containsKey(constantValue)); | 756 assert(!_constants.containsKey(constantValue)); |
757 String name = namer.constantName(constantValue); | 757 String name = namer.constantName(constantValue); |
758 String constantObject = namer.globalObjectForConstant(constantValue); | 758 String constantObject = namer.globalObjectForConstant(constantValue); |
759 Holder holder = _registry.registerHolder(constantObject); | 759 Holder holder = _registry.registerHolder(constantObject); |
760 Constant constant = new Constant(name, holder, constantValue); | 760 Constant constant = new Constant(name, holder, constantValue); |
761 _constants[constantValue] = constant; | 761 _constants[constantValue] = constant; |
762 } | 762 } |
763 } | 763 } |
764 } | 764 } |
OLD | NEW |