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 '../../closure.dart' show ClosureFieldElement; | 7 import '../../closure.dart' show ClosureTask, ClosureFieldElement; |
8 import '../../common.dart'; | 8 import '../../common.dart'; |
9 import '../../common/names.dart' show Names, Selectors; | 9 import '../../common/names.dart' show Names, Selectors; |
10 import '../../compiler.dart' show Compiler; | 10 import '../../compiler.dart' show Compiler; |
11 import '../../constants/values.dart' | 11 import '../../constants/values.dart' |
12 show ConstantValue, InterceptorConstantValue; | 12 show ConstantValue, InterceptorConstantValue; |
13 import '../../common_elements.dart' show CommonElements; | 13 import '../../common_elements.dart' show CommonElements; |
14 import '../../elements/resolution_types.dart' | 14 import '../../elements/resolution_types.dart' |
15 show ResolutionDartType, ResolutionFunctionType, ResolutionTypedefType; | 15 show ResolutionDartType, ResolutionFunctionType, ResolutionTypedefType; |
16 import '../../deferred_load.dart' show DeferredLoadTask, OutputUnit; | 16 import '../../deferred_load.dart' show DeferredLoadTask, OutputUnit; |
17 import '../../elements/elements.dart' | 17 import '../../elements/elements.dart' |
(...skipping 11 matching lines...) Expand all Loading... |
29 ParameterElement, | 29 ParameterElement, |
30 TypedefElement, | 30 TypedefElement, |
31 VariableElement; | 31 VariableElement; |
32 import '../../elements/entities.dart'; | 32 import '../../elements/entities.dart'; |
33 import '../../elements/resolution_types.dart' show Types; | 33 import '../../elements/resolution_types.dart' show Types; |
34 import '../../elements/types.dart' show DartType; | 34 import '../../elements/types.dart' show DartType; |
35 import '../../js/js.dart' as js; | 35 import '../../js/js.dart' as js; |
36 import '../../js_backend/backend.dart' | 36 import '../../js_backend/backend.dart' |
37 show | 37 show |
38 JavaScriptBackend, | 38 JavaScriptBackend, |
| 39 RuntimeTypesChecks, |
| 40 RuntimeTypesNeed, |
39 RuntimeTypesEncoder, | 41 RuntimeTypesEncoder, |
40 RuntimeTypesNeed, | 42 RuntimeTypesSubstitutions, |
41 SuperMemberData; | 43 SuperMemberData; |
42 import '../../js_backend/backend_usage.dart'; | 44 import '../../js_backend/backend_usage.dart'; |
43 import '../../js_backend/constant_handler_javascript.dart' | 45 import '../../js_backend/constant_handler_javascript.dart' |
44 show JavaScriptConstantCompiler; | 46 show JavaScriptConstantCompiler; |
45 import '../../js_backend/custom_elements_analysis.dart'; | 47 import '../../js_backend/custom_elements_analysis.dart'; |
46 import '../../js_backend/namer.dart' show Namer, StringBackedName; | 48 import '../../js_backend/namer.dart' show Namer, StringBackedName; |
47 import '../../js_backend/native_data.dart'; | 49 import '../../js_backend/native_data.dart'; |
48 import '../../js_backend/interceptor_data.dart'; | 50 import '../../js_backend/interceptor_data.dart'; |
49 import '../../js_backend/mirrors_data.dart'; | 51 import '../../js_backend/mirrors_data.dart'; |
| 52 import '../../js_backend/js_interop_analysis.dart'; |
50 import '../../native/enqueue.dart' show NativeCodegenEnqueuer; | 53 import '../../native/enqueue.dart' show NativeCodegenEnqueuer; |
51 import '../../options.dart'; | 54 import '../../options.dart'; |
52 import '../../universe/selector.dart' show Selector; | 55 import '../../universe/selector.dart' show Selector; |
53 import '../../universe/world_builder.dart' | 56 import '../../universe/world_builder.dart' |
54 show CodegenWorldBuilder, SelectorConstraints; | 57 show CodegenWorldBuilder, SelectorConstraints; |
55 import '../../world.dart' show ClosedWorld; | 58 import '../../world.dart' show ClosedWorld; |
56 import '../js_emitter.dart' | 59 import '../js_emitter.dart' |
57 show | 60 show |
58 ClassStubGenerator, | 61 ClassStubGenerator, |
59 CodeEmitterTask, | 62 CodeEmitterTask, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 this.collector = new Collector( | 101 this.collector = new Collector( |
99 compiler, _namer, closedWorld, rtiNeededClasses, emitter), | 102 compiler, _namer, closedWorld, rtiNeededClasses, emitter), |
100 this._registry = new Registry(compiler); | 103 this._registry = new Registry(compiler); |
101 | 104 |
102 JavaScriptBackend get _backend => _compiler.backend; | 105 JavaScriptBackend get _backend => _compiler.backend; |
103 CodegenWorldBuilder get _worldBuilder => _compiler.codegenWorldBuilder; | 106 CodegenWorldBuilder get _worldBuilder => _compiler.codegenWorldBuilder; |
104 DeferredLoadTask get _deferredLoadTask => _compiler.deferredLoadTask; | 107 DeferredLoadTask get _deferredLoadTask => _compiler.deferredLoadTask; |
105 Types get _types => _compiler.types; | 108 Types get _types => _compiler.types; |
106 CommonElements get _commonElements => _compiler.commonElements; | 109 CommonElements get _commonElements => _compiler.commonElements; |
107 CompilerOptions get _options => _compiler.options; | 110 CompilerOptions get _options => _compiler.options; |
| 111 ClosureTask get _closureToClassMapper => _compiler.closureToClassMapper; |
108 NativeCodegenEnqueuer get _nativeCodegenEnqueuer => | 112 NativeCodegenEnqueuer get _nativeCodegenEnqueuer => |
109 _backend.nativeCodegenEnqueuer; | 113 _backend.nativeCodegenEnqueuer; |
110 BackendUsage get _backendUsage => _backend.backendUsage; | 114 BackendUsage get _backendUsage => _backend.backendUsage; |
111 CodeEmitterTask get _emitter => _backend.emitter; | |
112 JavaScriptConstantCompiler get _constantHandler => _backend.constants; | 115 JavaScriptConstantCompiler get _constantHandler => _backend.constants; |
113 NativeData get _nativeData => _backend.nativeData; | 116 NativeData get _nativeData => _backend.nativeData; |
114 RuntimeTypesNeed get _rtiNeed => _backend.rtiNeed; | 117 RuntimeTypesNeed get _rtiNeed => _backend.rtiNeed; |
115 MirrorsData get _mirrorsData => _backend.mirrorsData; | 118 MirrorsData get _mirrorsData => _backend.mirrorsData; |
116 InterceptorData get _interceptorData => _backend.interceptorData; | 119 InterceptorData get _interceptorData => _backend.interceptorData; |
117 SuperMemberData get _superMemberData => _backend.superMemberData; | 120 SuperMemberData get _superMemberData => _backend.superMemberData; |
| 121 RuntimeTypesChecks get _rtiChecks => _backend.rtiChecks; |
118 RuntimeTypesEncoder get _rtiEncoder => _backend.rtiEncoder; | 122 RuntimeTypesEncoder get _rtiEncoder => _backend.rtiEncoder; |
| 123 RuntimeTypesSubstitutions get _rtiSubstitutions => _backend.rtiSubstitutions; |
| 124 JsInteropAnalysis get _jsInteropAnalysis => _backend.jsInteropAnalysis; |
119 OneShotInterceptorData get _oneShotInterceptorData => | 125 OneShotInterceptorData get _oneShotInterceptorData => |
120 _backend.oneShotInterceptorData; | 126 _backend.oneShotInterceptorData; |
121 CustomElementsCodegenAnalysis get _customElementsCodegenAnalysis => | 127 CustomElementsCodegenAnalysis get _customElementsCodegenAnalysis => |
122 _backend.customElementsCodegenAnalysis; | 128 _backend.customElementsCodegenAnalysis; |
123 | 129 |
124 /// Mapping from [ClassElement] to constructed [Class]. We need this to | 130 /// Mapping from [ClassElement] to constructed [Class]. We need this to |
125 /// update the superclass in the [Class]. | 131 /// update the superclass in the [Class]. |
126 final Map<ClassElement, Class> _classes = <ClassElement, Class>{}; | 132 final Map<ClassElement, Class> _classes = <ClassElement, Class>{}; |
127 | 133 |
128 /// Mapping from [OutputUnit] to constructed [Fragment]. We need this to | 134 /// Mapping from [OutputUnit] to constructed [Fragment]. We need this to |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 .map((OutputUnit unit) => _outputs[unit]) | 244 .map((OutputUnit unit) => _outputs[unit]) |
239 .toList(growable: false); | 245 .toList(growable: false); |
240 }); | 246 }); |
241 return loadMap; | 247 return loadMap; |
242 } | 248 } |
243 | 249 |
244 js.Expression _buildTypeToInterceptorMap() { | 250 js.Expression _buildTypeToInterceptorMap() { |
245 InterceptorStubGenerator stubGenerator = new InterceptorStubGenerator( | 251 InterceptorStubGenerator stubGenerator = new InterceptorStubGenerator( |
246 _options, | 252 _options, |
247 _commonElements, | 253 _commonElements, |
248 _emitter, | 254 _task, |
249 _nativeCodegenEnqueuer, | 255 _nativeCodegenEnqueuer, |
250 _constantHandler, | 256 _constantHandler, |
251 _namer, | 257 _namer, |
252 _nativeData, | 258 _nativeData, |
253 _interceptorData, | 259 _interceptorData, |
254 _oneShotInterceptorData, | 260 _oneShotInterceptorData, |
255 _customElementsCodegenAnalysis, | 261 _customElementsCodegenAnalysis, |
256 _worldBuilder, | 262 _worldBuilder, |
257 _closedWorld); | 263 _closedWorld); |
258 return stubGenerator.generateTypeToInterceptorMap(); | 264 return stubGenerator.generateTypeToInterceptorMap(); |
259 } | 265 } |
260 | 266 |
261 MainFragment _buildMainFragment(LibrariesMap librariesMap) { | 267 MainFragment _buildMainFragment(LibrariesMap librariesMap) { |
262 // Construct the main output from the libraries and the registered holders. | 268 // Construct the main output from the libraries and the registered holders. |
263 MainFragment result = new MainFragment( | 269 MainFragment result = new MainFragment( |
264 librariesMap.outputUnit, | 270 librariesMap.outputUnit, |
265 "", // The empty string is the name for the main output file. | 271 "", // The empty string is the name for the main output file. |
266 _buildInvokeMain(), | 272 _buildInvokeMain(), |
267 _buildLibraries(librariesMap), | 273 _buildLibraries(librariesMap), |
268 _buildStaticNonFinalFields(librariesMap), | 274 _buildStaticNonFinalFields(librariesMap), |
269 _buildStaticLazilyInitializedFields(librariesMap), | 275 _buildStaticLazilyInitializedFields(librariesMap), |
270 _buildConstants(librariesMap)); | 276 _buildConstants(librariesMap)); |
271 _outputs[librariesMap.outputUnit] = result; | 277 _outputs[librariesMap.outputUnit] = result; |
272 return result; | 278 return result; |
273 } | 279 } |
274 | 280 |
275 js.Statement _buildInvokeMain() { | 281 js.Statement _buildInvokeMain() { |
276 if (_compiler.isMockCompilation) return js.js.comment("Mock compilation"); | 282 if (_compiler.isMockCompilation) return js.js.comment("Mock compilation"); |
277 | 283 |
278 MainCallStubGenerator generator = | 284 MainCallStubGenerator generator = new MainCallStubGenerator( |
279 new MainCallStubGenerator(_backend, _emitter); | 285 _commonElements, _task.emitter, _backendUsage); |
280 return generator.generateInvokeMain(_compiler.mainFunction); | 286 return generator.generateInvokeMain(_compiler.mainFunction); |
281 } | 287 } |
282 | 288 |
283 DeferredFragment _buildDeferredFragment(LibrariesMap librariesMap) { | 289 DeferredFragment _buildDeferredFragment(LibrariesMap librariesMap) { |
284 DeferredFragment result = new DeferredFragment( | 290 DeferredFragment result = new DeferredFragment( |
285 librariesMap.outputUnit, | 291 librariesMap.outputUnit, |
286 _backend.deferredPartFileName(librariesMap.name, addExtension: false), | 292 _backend.deferredPartFileName(librariesMap.name, addExtension: false), |
287 librariesMap.name, | 293 librariesMap.name, |
288 _buildLibraries(librariesMap), | 294 _buildLibraries(librariesMap), |
289 _buildStaticNonFinalFields(librariesMap), | 295 _buildStaticNonFinalFields(librariesMap), |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 // if it does not we can suppress it completely. | 551 // if it does not we can suppress it completely. |
546 onlyForRti = true; | 552 onlyForRti = true; |
547 } | 553 } |
548 | 554 |
549 List<Method> methods = []; | 555 List<Method> methods = []; |
550 List<StubMethod> callStubs = <StubMethod>[]; | 556 List<StubMethod> callStubs = <StubMethod>[]; |
551 | 557 |
552 ClassStubGenerator classStubGenerator = new ClassStubGenerator( | 558 ClassStubGenerator classStubGenerator = new ClassStubGenerator( |
553 _namer, _backend, _worldBuilder, _closedWorld, | 559 _namer, _backend, _worldBuilder, _closedWorld, |
554 enableMinification: _options.enableMinification); | 560 enableMinification: _options.enableMinification); |
555 RuntimeTypeGenerator runtimeTypeGenerator = | 561 RuntimeTypeGenerator runtimeTypeGenerator = new RuntimeTypeGenerator( |
556 new RuntimeTypeGenerator(_compiler, _task, _namer); | 562 _commonElements, |
| 563 _closureToClassMapper, |
| 564 _task, |
| 565 _namer, |
| 566 _nativeData, |
| 567 _rtiChecks, |
| 568 _rtiEncoder, |
| 569 _rtiNeed, |
| 570 _rtiSubstitutions, |
| 571 _jsInteropAnalysis); |
557 | 572 |
558 void visitMember(ClassElement enclosing, MemberElement member) { | 573 void visitMember(ClassElement enclosing, MemberElement member) { |
559 assert(invariant(element, member.isDeclaration)); | 574 assert(invariant(element, member.isDeclaration)); |
560 assert(invariant(element, element == enclosing)); | 575 assert(invariant(element, element == enclosing)); |
561 | 576 |
562 if (Elements.isNonAbstractInstanceMember(member)) { | 577 if (Elements.isNonAbstractInstanceMember(member)) { |
563 // TODO(herhut): Remove once _buildMethod can no longer return null. | 578 // TODO(herhut): Remove once _buildMethod can no longer return null. |
564 Method method = _buildMethod(member); | 579 Method method = _buildMethod(member); |
565 if (method != null) methods.add(method); | 580 if (method != null) methods.add(method); |
566 } | 581 } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 canBeReflected: canBeReflected, | 828 canBeReflected: canBeReflected, |
814 requiredParameterCount: requiredParameterCount, | 829 requiredParameterCount: requiredParameterCount, |
815 optionalParameterDefaultValues: optionalParameterDefaultValues, | 830 optionalParameterDefaultValues: optionalParameterDefaultValues, |
816 functionType: functionType); | 831 functionType: functionType); |
817 } | 832 } |
818 | 833 |
819 js.Expression _generateFunctionType( | 834 js.Expression _generateFunctionType( |
820 ResolutionDartType type, OutputUnit outputUnit) { | 835 ResolutionDartType type, OutputUnit outputUnit) { |
821 if (type.containsTypeVariables) { | 836 if (type.containsTypeVariables) { |
822 js.Expression thisAccess = js.js(r'this.$receiver'); | 837 js.Expression thisAccess = js.js(r'this.$receiver'); |
823 return _rtiEncoder.getSignatureEncoding( | 838 return _rtiEncoder.getSignatureEncoding(_task.emitter, type, thisAccess); |
824 _emitter.emitter, type, thisAccess); | |
825 } else { | 839 } else { |
826 return _emitter.metadataCollector | 840 return _task.metadataCollector.reifyTypeForOutputUnit(type, outputUnit); |
827 .reifyTypeForOutputUnit(type, outputUnit); | |
828 } | 841 } |
829 } | 842 } |
830 | 843 |
831 List<ParameterStubMethod> _generateParameterStubs( | 844 List<ParameterStubMethod> _generateParameterStubs( |
832 MethodElement element, bool canTearOff) { | 845 MethodElement element, bool canTearOff) { |
833 if (!_methodNeedsStubs(element)) return const <ParameterStubMethod>[]; | 846 if (!_methodNeedsStubs(element)) return const <ParameterStubMethod>[]; |
834 | 847 |
835 ParameterStubGenerator generator = | 848 ParameterStubGenerator generator = |
836 new ParameterStubGenerator(_compiler, _namer, _backend, _closedWorld); | 849 new ParameterStubGenerator(_compiler, _namer, _backend, _closedWorld); |
837 return generator.generateParameterStubs(element, canTearOff: canTearOff); | 850 return generator.generateParameterStubs(element, canTearOff: canTearOff); |
(...skipping 20 matching lines...) Expand all Loading... |
858 Class cls = _classes[element]; | 871 Class cls = _classes[element]; |
859 if (cls != null) cls.isEager = true; | 872 if (cls != null) cls.isEager = true; |
860 } | 873 } |
861 } | 874 } |
862 } | 875 } |
863 | 876 |
864 Iterable<StaticStubMethod> _generateGetInterceptorMethods() { | 877 Iterable<StaticStubMethod> _generateGetInterceptorMethods() { |
865 InterceptorStubGenerator stubGenerator = new InterceptorStubGenerator( | 878 InterceptorStubGenerator stubGenerator = new InterceptorStubGenerator( |
866 _options, | 879 _options, |
867 _commonElements, | 880 _commonElements, |
868 _emitter, | 881 _task, |
869 _nativeCodegenEnqueuer, | 882 _nativeCodegenEnqueuer, |
870 _constantHandler, | 883 _constantHandler, |
871 _namer, | 884 _namer, |
872 _nativeData, | 885 _nativeData, |
873 _interceptorData, | 886 _interceptorData, |
874 _oneShotInterceptorData, | 887 _oneShotInterceptorData, |
875 _customElementsCodegenAnalysis, | 888 _customElementsCodegenAnalysis, |
876 _worldBuilder, | 889 _worldBuilder, |
877 _closedWorld); | 890 _closedWorld); |
878 | 891 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 needsCheckedSetter)); | 950 needsCheckedSetter)); |
938 }); | 951 }); |
939 | 952 |
940 return fields; | 953 return fields; |
941 } | 954 } |
942 | 955 |
943 Iterable<StaticStubMethod> _generateOneShotInterceptors() { | 956 Iterable<StaticStubMethod> _generateOneShotInterceptors() { |
944 InterceptorStubGenerator stubGenerator = new InterceptorStubGenerator( | 957 InterceptorStubGenerator stubGenerator = new InterceptorStubGenerator( |
945 _options, | 958 _options, |
946 _commonElements, | 959 _commonElements, |
947 _emitter, | 960 _task, |
948 _nativeCodegenEnqueuer, | 961 _nativeCodegenEnqueuer, |
949 _constantHandler, | 962 _constantHandler, |
950 _namer, | 963 _namer, |
951 _nativeData, | 964 _nativeData, |
952 _interceptorData, | 965 _interceptorData, |
953 _oneShotInterceptorData, | 966 _oneShotInterceptorData, |
954 _customElementsCodegenAnalysis, | 967 _customElementsCodegenAnalysis, |
955 _worldBuilder, | 968 _worldBuilder, |
956 _closedWorld); | 969 _closedWorld); |
957 | 970 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 Constant constant = new Constant(name, holder, constantValue); | 1046 Constant constant = new Constant(name, holder, constantValue); |
1034 _constants[constantValue] = constant; | 1047 _constants[constantValue] = constant; |
1035 } | 1048 } |
1036 } | 1049 } |
1037 | 1050 |
1038 Holder _registerStaticStateHolder() { | 1051 Holder _registerStaticStateHolder() { |
1039 return _registry.registerHolder(_namer.staticStateHolder, | 1052 return _registry.registerHolder(_namer.staticStateHolder, |
1040 isStaticStateHolder: true); | 1053 isStaticStateHolder: true); |
1041 } | 1054 } |
1042 } | 1055 } |
OLD | NEW |