Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_emitter/program_builder.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/program_builder.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/program_builder.dart |
| index 277fb39299616b40e1a3203d1e1e5bc13970accd..53794e30e3e481b24bcab52591e3106830976902 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/js_emitter/program_builder.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/js_emitter/program_builder.dart |
| @@ -8,7 +8,11 @@ import 'model.dart'; |
| import '../common.dart'; |
| import '../js/js.dart' as js; |
| -import '../js_backend/js_backend.dart' show Namer, JavaScriptBackend; |
| +import '../js_backend/js_backend.dart' show |
| + Namer, |
| + JavaScriptBackend, |
| + JavaScriptConstantCompiler; |
| + |
| import '../js_emitter/js_emitter.dart' as emitterTask show |
| CodeEmitterTask, |
| Emitter; |
| @@ -49,6 +53,7 @@ class ProgramBuilder { |
| Program buildProgram() { |
| _task.outputClassLists.forEach(_registry.registerElements); |
| _task.outputStaticLists.forEach(_registry.registerElements); |
| + _task.outputConstantLists.forEach(_registerConstants); |
| // TODO(kasperl): There's code that implicitly needs access to the special |
| // $ holder so we have to register that. Can we track if we have to? |
| @@ -96,6 +101,7 @@ class ProgramBuilder { |
| "", // The empty string is the name for the main output file. |
| namer.elementAccess(_compiler.mainFunction), |
| _buildLibraries(fragment), |
| + _buildStaticNonFinalFields(fragment), |
| _buildConstants(fragment), |
| _registry.holders.toList(growable: false)); |
| _outputs[fragment.outputUnit] = result; |
| @@ -118,6 +124,7 @@ class ProgramBuilder { |
| _outputFileName(fragment.name), fragment.name, |
| mainOutput, |
| _buildLibraries(fragment), |
| + _buildStaticNonFinalFields(fragment), |
| _buildConstants(fragment)); |
| _outputs[fragment.outputUnit] = result; |
| return result; |
| @@ -127,15 +134,37 @@ class ProgramBuilder { |
| List<ConstantValue> constantValues = |
| _task.outputConstantLists[fragment.outputUnit]; |
| if (constantValues == null) return const <Constant>[]; |
| - return constantValues.map((ConstantValue constantValue) { |
| - assert(!_constants.containsKey(constantValue)); |
| - String name = namer.constantName(constantValue); |
| - String constantObject = namer.globalObjectForConstant(constantValue); |
| - Holder holder = _registry.registerHolder(constantObject); |
| - Constant constant = new Constant(name, holder, constantValue); |
| - _constants[constantValue] = constant; |
| - return constant; |
| - }).toList(); |
| + return constantValues.map((ConstantValue value) => _constants[value]) |
| + .toList(growable: false); |
| + } |
| + |
| + List<StaticField> _buildStaticNonFinalFields(Fragment fragment) { |
| + // TODO(floitsch): handle static non-final fields correctly with deferred |
| + // libraries. |
| + if (!fragment.isMainFragment) return const <StaticField>[]; |
| + JavaScriptConstantCompiler handler = backend.constants; |
| + Iterable<VariableElement> staticNonFinalFields = |
| + handler.getStaticNonFinalFieldsForEmission(); |
| + return Elements.sortedByPosition(staticNonFinalFields).map |
|
kasperl
2014/10/17 06:47:04
Maybe turn the closure passed to map here into a p
floitsch
2014/10/17 09:25:56
Done.
|
| + ((Element element) { |
| + ConstantValue initialValue = handler.getInitialValueFor(element).value; |
| + js.Expression code = _task.emitter.constantReference(initialValue); |
| + String name = namer.getNameOfGlobalField(element); |
| + bool isFinal = false; |
| + bool isLazy = false; |
| + return new StaticField(name, _registry.registerHolder(r'$'), code, |
| + isFinal, isLazy); |
| + }).toList(growable: false); |
| + } |
| + |
| + List<StaticField> _buildStaticLazilyInitializedFields(Fragment fragment) { |
| + JavaScriptConstantCompiler handler = backend.constants; |
| + List<VariableElement> lazyFields = |
| + handler.getLazilyInitializedFieldsForEmission(); |
| + // TODO(floitsch): handle static lazy finals correctly with deferred |
| + // libraries. |
| + if (!fragment.isMainFragment) return const <StaticField>[]; |
| + throw new UnimplementedError("lazy statics"); |
| } |
| List<Library> _buildLibraries(Fragment fragment) { |
| @@ -206,4 +235,17 @@ class ProgramBuilder { |
| js.Expression code = js.string("<<unimplemented>>"); |
| return new StaticMethod(name, _registry.registerHolder(holder), code); |
| } |
| + |
| + void _registerConstants(OutputUnit outputUnit, |
|
floitsch
2014/10/16 14:27:55
I think I can simplify this in a later CL: turns o
|
| + List<ConstantValue> constantValues) { |
| + if (constantValues == null) return; |
| + for (ConstantValue constantValue in constantValues) { |
| + assert(!_constants.containsKey(constantValue)); |
| + String name = namer.constantName(constantValue); |
| + String constantObject = namer.globalObjectForConstant(constantValue); |
| + Holder holder = _registry.registerHolder(constantObject); |
| + Constant constant = new Constant(name, holder, constantValue); |
| + _constants[constantValue] = constant; |
| + }; |
| + } |
| } |