| 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.full_emitter; | 5 library dart2js.js_emitter.full_emitter; |
| 6 | 6 |
| 7 import 'dart:collection' show HashMap; | 7 import 'dart:collection' show HashMap; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| 11 import 'package:js_runtime/shared/embedded_names.dart' | 11 import 'package:js_runtime/shared/embedded_names.dart' |
| 12 show JsBuiltin, JsGetName; | 12 show JsBuiltin, JsGetName; |
| 13 | 13 |
| 14 import '../../../compiler_new.dart'; | 14 import '../../../compiler_new.dart'; |
| 15 import '../../common.dart'; | 15 import '../../common.dart'; |
| 16 import '../../compiler.dart' show Compiler; | 16 import '../../compiler.dart' show Compiler; |
| 17 import '../../constants/values.dart'; | 17 import '../../constants/values.dart'; |
| 18 import '../../common_elements.dart' show CommonElements, ElementEnvironment; | 18 import '../../common_elements.dart' show CommonElements, ElementEnvironment; |
| 19 import '../../elements/resolution_types.dart' show ResolutionDartType; | 19 import '../../elements/resolution_types.dart' show ResolutionDartType; |
| 20 import '../../deferred_load.dart' show OutputUnit; | 20 import '../../deferred_load.dart' show OutputUnit; |
| 21 import '../../elements/elements.dart' | 21 import '../../elements/elements.dart' |
| 22 show ClassElement, ConstructorBodyElement, LibraryElement, TypedefElement; | 22 show |
| 23 ClassElement, |
| 24 ConstructorBodyElement, |
| 25 FieldElement, |
| 26 LibraryElement, |
| 27 MethodElement, |
| 28 TypedefElement; |
| 23 import '../../elements/entities.dart'; | 29 import '../../elements/entities.dart'; |
| 24 import '../../elements/entity_utils.dart' as utils; | 30 import '../../elements/entity_utils.dart' as utils; |
| 25 import '../../elements/names.dart'; | 31 import '../../elements/names.dart'; |
| 26 import '../../hash/sha1.dart' show Hasher; | 32 import '../../hash/sha1.dart' show Hasher; |
| 27 import '../../io/code_output.dart'; | 33 import '../../io/code_output.dart'; |
| 28 import '../../io/location_provider.dart' show LocationCollector; | 34 import '../../io/location_provider.dart' show LocationCollector; |
| 29 import '../../io/source_map_builder.dart' show SourceMapBuilder; | 35 import '../../io/source_map_builder.dart' show SourceMapBuilder; |
| 30 import '../../js/js.dart' as jsAst; | 36 import '../../js/js.dart' as jsAst; |
| 31 import '../../js/js.dart' show js; | 37 import '../../js/js.dart' show js; |
| 32 import '../../js_backend/js_backend.dart' | 38 import '../../js_backend/js_backend.dart' |
| 33 show | 39 show |
| 34 ConstantEmitter, | 40 ConstantEmitter, |
| 35 JavaScriptBackend, | 41 JavaScriptBackend, |
| 42 JavaScriptConstantCompiler, |
| 36 Namer, | 43 Namer, |
| 37 SetterName, | 44 SetterName, |
| 38 TypeVariableCodegenAnalysis; | 45 TypeVariableCodegenAnalysis; |
| 39 import '../../js_backend/native_data.dart'; | 46 import '../../js_backend/native_data.dart'; |
| 40 import '../../universe/call_structure.dart' show CallStructure; | 47 import '../../universe/call_structure.dart' show CallStructure; |
| 41 import '../../universe/selector.dart' show Selector; | 48 import '../../universe/selector.dart' show Selector; |
| 42 import '../../universe/world_builder.dart' show CodegenWorldBuilder; | 49 import '../../universe/world_builder.dart' show CodegenWorldBuilder; |
| 43 import '../../util/uri_extras.dart' show relativize; | 50 import '../../util/uri_extras.dart' show relativize; |
| 44 import '../../world.dart' show ClosedWorld; | 51 import '../../world.dart' show ClosedWorld; |
| 45 import '../constant_ordering.dart' show deepCompareConstants; | 52 import '../constant_ordering.dart' show deepCompareConstants; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 /// that is, some function was needed for reflection, had stubs, or had a | 118 /// that is, some function was needed for reflection, had stubs, or had a |
| 112 /// super alias. | 119 /// super alias. |
| 113 bool needsStructuredMemberInfo = false; | 120 bool needsStructuredMemberInfo = false; |
| 114 | 121 |
| 115 final Namer namer; | 122 final Namer namer; |
| 116 ConstantEmitter constantEmitter; | 123 ConstantEmitter constantEmitter; |
| 117 NativeEmitter get nativeEmitter => task.nativeEmitter; | 124 NativeEmitter get nativeEmitter => task.nativeEmitter; |
| 118 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry; | 125 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry; |
| 119 CommonElements get commonElements => _closedWorld.commonElements; | 126 CommonElements get commonElements => _closedWorld.commonElements; |
| 120 ElementEnvironment get _elementEnvironment => _closedWorld.elementEnvironment; | 127 ElementEnvironment get _elementEnvironment => _closedWorld.elementEnvironment; |
| 121 CodegenWorldBuilder get _worldBuilder => compiler.codegenWorldBuilder; | |
| 122 | 128 |
| 123 // The full code that is written to each hunk part-file. | 129 // The full code that is written to each hunk part-file. |
| 124 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); | 130 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); |
| 125 | 131 |
| 126 String classesCollector; | 132 String classesCollector; |
| 127 final Map<jsAst.Name, String> mangledFieldNames = | 133 final Map<jsAst.Name, String> mangledFieldNames = |
| 128 new HashMap<jsAst.Name, String>(); | 134 new HashMap<jsAst.Name, String>(); |
| 129 final Map<jsAst.Name, String> mangledGlobalFieldNames = | 135 final Map<jsAst.Name, String> mangledGlobalFieldNames = |
| 130 new HashMap<jsAst.Name, String>(); | 136 new HashMap<jsAst.Name, String>(); |
| 131 final Set<jsAst.Name> recordedMangledNames = new Set<jsAst.Name>(); | 137 final Set<jsAst.Name> recordedMangledNames = new Set<jsAst.Name>(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 final bool generateSourceMap; | 177 final bool generateSourceMap; |
| 172 | 178 |
| 173 Emitter(this.compiler, this.namer, this._closedWorld, this.generateSourceMap, | 179 Emitter(this.compiler, this.namer, this._closedWorld, this.generateSourceMap, |
| 174 this.task, this._sorter) | 180 this.task, this._sorter) |
| 175 : classEmitter = new ClassEmitter(_closedWorld), | 181 : classEmitter = new ClassEmitter(_closedWorld), |
| 176 interceptorEmitter = new InterceptorEmitter(_closedWorld), | 182 interceptorEmitter = new InterceptorEmitter(_closedWorld), |
| 177 nsmEmitter = new NsmEmitter(_closedWorld) { | 183 nsmEmitter = new NsmEmitter(_closedWorld) { |
| 178 constantEmitter = new ConstantEmitter( | 184 constantEmitter = new ConstantEmitter( |
| 179 compiler.options, | 185 compiler.options, |
| 180 _closedWorld.commonElements, | 186 _closedWorld.commonElements, |
| 181 compiler.codegenWorldBuilder, | |
| 182 compiler.backend.rtiNeed, | 187 compiler.backend.rtiNeed, |
| 183 compiler.backend.rtiEncoder, | 188 compiler.backend.rtiEncoder, |
| 184 namer, | 189 namer, |
| 185 task, | 190 task, |
| 186 this.constantReference, | 191 this.constantReference, |
| 187 constantListGenerator); | 192 constantListGenerator); |
| 188 containerBuilder.emitter = this; | 193 containerBuilder.emitter = this; |
| 189 classEmitter.emitter = this; | 194 classEmitter.emitter = this; |
| 190 nsmEmitter.emitter = this; | 195 nsmEmitter.emitter = this; |
| 191 interceptorEmitter.emitter = this; | 196 interceptorEmitter.emitter = this; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 jsAst.Expression generateEmbeddedGlobalAccess(String global) { | 296 jsAst.Expression generateEmbeddedGlobalAccess(String global) { |
| 292 return js(generateEmbeddedGlobalAccessString(global)); | 297 return js(generateEmbeddedGlobalAccessString(global)); |
| 293 } | 298 } |
| 294 | 299 |
| 295 String generateEmbeddedGlobalAccessString(String global) { | 300 String generateEmbeddedGlobalAccessString(String global) { |
| 296 // TODO(floitsch): don't use 'init' as global embedder storage. | 301 // TODO(floitsch): don't use 'init' as global embedder storage. |
| 297 return '$initName.$global'; | 302 return '$initName.$global'; |
| 298 } | 303 } |
| 299 | 304 |
| 300 @override | 305 @override |
| 301 jsAst.Expression isolateLazyInitializerAccess(FieldEntity element) { | 306 jsAst.Expression isolateLazyInitializerAccess(FieldElement element) { |
| 302 return jsAst.js('#.#', [ | 307 return jsAst.js('#.#', [ |
| 303 namer.globalObjectForMember(element), | 308 namer.globalObjectForMember(element), |
| 304 namer.lazyInitializerName(element) | 309 namer.lazyInitializerName(element) |
| 305 ]); | 310 ]); |
| 306 } | 311 } |
| 307 | 312 |
| 308 @override | 313 @override |
| 309 jsAst.Expression isolateStaticClosureAccess(FunctionEntity element) { | 314 jsAst.Expression isolateStaticClosureAccess(MethodElement element) { |
| 310 return jsAst.js('#.#()', [ | 315 return jsAst.js('#.#()', [ |
| 311 namer.globalObjectForMember(element), | 316 namer.globalObjectForMember(element), |
| 312 namer.staticClosureName(element) | 317 namer.staticClosureName(element) |
| 313 ]); | 318 ]); |
| 314 } | 319 } |
| 315 | 320 |
| 316 @override | 321 @override |
| 317 jsAst.PropertyAccess prototypeAccess( | 322 jsAst.PropertyAccess prototypeAccess( |
| 318 ClassElement element, bool hasBeenInstantiated) { | 323 ClassElement element, bool hasBeenInstantiated) { |
| 319 return jsAst.js('#.prototype', constructorAccess(element)); | 324 return jsAst.js('#.prototype', constructorAccess(element)); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 containerBuilder.addMemberMethod(method, builder); | 626 containerBuilder.addMemberMethod(method, builder); |
| 622 getStaticMethodDescriptor(element, fragment) | 627 getStaticMethodDescriptor(element, fragment) |
| 623 .properties | 628 .properties |
| 624 .addAll(builder.properties); | 629 .addAll(builder.properties); |
| 625 } | 630 } |
| 626 } | 631 } |
| 627 | 632 |
| 628 jsAst.Statement buildStaticNonFinalFieldInitializations( | 633 jsAst.Statement buildStaticNonFinalFieldInitializations( |
| 629 OutputUnit outputUnit) { | 634 OutputUnit outputUnit) { |
| 630 jsAst.Statement buildInitialization( | 635 jsAst.Statement buildInitialization( |
| 631 FieldEntity element, jsAst.Expression initialValue) { | 636 FieldElement element, jsAst.Expression initialValue) { |
| 632 return js.statement('${namer.staticStateHolder}.# = #', | 637 return js.statement('${namer.staticStateHolder}.# = #', |
| 633 [namer.globalPropertyNameForMember(element), initialValue]); | 638 [namer.globalPropertyNameForMember(element), initialValue]); |
| 634 } | 639 } |
| 635 | 640 |
| 636 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); | 641 bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit); |
| 642 JavaScriptConstantCompiler handler = backend.constants; |
| 637 List<jsAst.Statement> parts = <jsAst.Statement>[]; | 643 List<jsAst.Statement> parts = <jsAst.Statement>[]; |
| 638 | 644 |
| 639 Iterable<FieldEntity> fields = outputStaticNonFinalFieldLists[outputUnit]; | 645 Iterable<FieldEntity> fields = outputStaticNonFinalFieldLists[outputUnit]; |
| 640 // If the outputUnit does not contain any static non-final fields, then | 646 // If the outputUnit does not contain any static non-final fields, then |
| 641 // [fields] is `null`. | 647 // [fields] is `null`. |
| 642 if (fields != null) { | 648 if (fields != null) { |
| 643 for (FieldEntity element in fields) { | 649 for (FieldElement element in fields) { |
| 644 reporter.withCurrentElement(element, () { | 650 reporter.withCurrentElement(element, () { |
| 645 ConstantValue constant = | 651 ConstantValue constant = handler.getConstantValue(element.constant); |
| 646 _worldBuilder.getConstantFieldInitializer(element); | |
| 647 parts.add(buildInitialization(element, constantReference(constant))); | 652 parts.add(buildInitialization(element, constantReference(constant))); |
| 648 }); | 653 }); |
| 649 } | 654 } |
| 650 } | 655 } |
| 651 | 656 |
| 652 if (inMainUnit && outputStaticNonFinalFieldLists.length > 1) { | 657 if (inMainUnit && outputStaticNonFinalFieldLists.length > 1) { |
| 653 // In the main output-unit we output a stub initializer for deferred | 658 // In the main output-unit we output a stub initializer for deferred |
| 654 // variables, so that `isolateProperties` stays a fast object. | 659 // variables, so that `isolateProperties` stays a fast object. |
| 655 outputStaticNonFinalFieldLists | 660 outputStaticNonFinalFieldLists |
| 656 .forEach((OutputUnit fieldsOutputUnit, Iterable<FieldEntity> fields) { | 661 .forEach((OutputUnit fieldsOutputUnit, Iterable<FieldEntity> fields) { |
| (...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1967 // data. | 1972 // data. |
| 1968 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 1973 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
| 1969 "needed for a given deferred library import."; | 1974 "needed for a given deferred library import."; |
| 1970 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 1975 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
| 1971 compiler.outputProvider( | 1976 compiler.outputProvider( |
| 1972 compiler.options.deferredMapUri.path, '', OutputType.info) | 1977 compiler.options.deferredMapUri.path, '', OutputType.info) |
| 1973 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 1978 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
| 1974 ..close(); | 1979 ..close(); |
| 1975 } | 1980 } |
| 1976 } | 1981 } |
| OLD | NEW |