OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.startup_emitter.model_emitter; | 5 library dart2js.js_emitter.startup_emitter.model_emitter; |
6 | 6 |
7 import 'dart:convert' show JsonEncoder; | 7 import 'dart:convert' show JsonEncoder; |
8 | 8 |
9 import 'package:js_runtime/shared/embedded_names.dart' | 9 import 'package:js_runtime/shared/embedded_names.dart' |
10 show | 10 show |
(...skipping 26 matching lines...) Expand all Loading... |
37 import '../../common_elements.dart' show CommonElements; | 37 import '../../common_elements.dart' show CommonElements; |
38 import '../../elements/elements.dart' show ClassElement, MethodElement; | 38 import '../../elements/elements.dart' show ClassElement, MethodElement; |
39 import '../../hash/sha1.dart' show Hasher; | 39 import '../../hash/sha1.dart' show Hasher; |
40 import '../../io/code_output.dart'; | 40 import '../../io/code_output.dart'; |
41 import '../../io/location_provider.dart' show LocationCollector; | 41 import '../../io/location_provider.dart' show LocationCollector; |
42 import '../../io/source_map_builder.dart' show SourceMapBuilder; | 42 import '../../io/source_map_builder.dart' show SourceMapBuilder; |
43 import '../../js/js.dart' as js; | 43 import '../../js/js.dart' as js; |
44 import '../../js_backend/js_backend.dart' | 44 import '../../js_backend/js_backend.dart' |
45 show JavaScriptBackend, Namer, ConstantEmitter, StringBackedName; | 45 show JavaScriptBackend, Namer, ConstantEmitter, StringBackedName; |
46 import '../../js_backend/interceptor_data.dart'; | 46 import '../../js_backend/interceptor_data.dart'; |
| 47 import '../../world.dart'; |
| 48 import '../code_emitter_task.dart'; |
47 import '../constant_ordering.dart' show deepCompareConstants; | 49 import '../constant_ordering.dart' show deepCompareConstants; |
48 import '../headers.dart'; | 50 import '../headers.dart'; |
49 import '../js_emitter.dart' show NativeEmitter; | 51 import '../js_emitter.dart' show NativeEmitter; |
50 import '../js_emitter.dart' show buildTearOffCode, NativeGenerator; | 52 import '../js_emitter.dart' show buildTearOffCode, NativeGenerator; |
51 import '../model.dart'; | 53 import '../model.dart'; |
52 | 54 |
53 part 'deferred_fragment_hash.dart'; | 55 part 'deferred_fragment_hash.dart'; |
54 part 'fragment_emitter.dart'; | 56 part 'fragment_emitter.dart'; |
55 | 57 |
56 class ModelEmitter { | 58 class ModelEmitter { |
57 final Compiler compiler; | 59 final Compiler compiler; |
58 final Namer namer; | 60 final Namer namer; |
59 ConstantEmitter constantEmitter; | 61 ConstantEmitter constantEmitter; |
60 final NativeEmitter nativeEmitter; | 62 final NativeEmitter nativeEmitter; |
61 final bool shouldGenerateSourceMap; | 63 final bool shouldGenerateSourceMap; |
62 final InterceptorData _interceptorData; | 64 final ClosedWorld _closedWorld; |
63 | 65 |
64 // The full code that is written to each hunk part-file. | 66 // The full code that is written to each hunk part-file. |
65 final Map<Fragment, CodeOutput> outputBuffers = <Fragment, CodeOutput>{}; | 67 final Map<Fragment, CodeOutput> outputBuffers = <Fragment, CodeOutput>{}; |
66 | 68 |
67 JavaScriptBackend get backend => compiler.backend; | 69 JavaScriptBackend get backend => compiler.backend; |
68 | 70 |
69 /// For deferred loading we communicate the initializers via this global var. | 71 /// For deferred loading we communicate the initializers via this global var. |
70 static const String deferredInitializersGlobal = | 72 static const String deferredInitializersGlobal = |
71 r"$__dart_deferred_initializers__"; | 73 r"$__dart_deferred_initializers__"; |
72 | 74 |
73 static const String partExtension = "part"; | 75 static const String partExtension = "part"; |
74 static const String deferredExtension = "part.js"; | 76 static const String deferredExtension = "part.js"; |
75 | 77 |
76 static const String typeNameProperty = r"builtin$cls"; | 78 static const String typeNameProperty = r"builtin$cls"; |
77 | 79 |
78 ModelEmitter(this.compiler, this.namer, this.nativeEmitter, | 80 ModelEmitter(this.compiler, this.namer, this.nativeEmitter, this._closedWorld, |
79 this._interceptorData, this.shouldGenerateSourceMap) { | 81 CodeEmitterTask task, this.shouldGenerateSourceMap) { |
80 this.constantEmitter = new ConstantEmitter( | 82 this.constantEmitter = new ConstantEmitter( |
81 compiler, namer, this.generateConstantReference, constantListGenerator); | 83 compiler.options, |
| 84 _closedWorld.commonElements, |
| 85 compiler.backend.rtiNeed, |
| 86 compiler.backend.rtiEncoder, |
| 87 namer, |
| 88 task, |
| 89 this.generateConstantReference, |
| 90 constantListGenerator); |
82 } | 91 } |
83 | 92 |
84 DiagnosticReporter get reporter => compiler.reporter; | 93 DiagnosticReporter get reporter => compiler.reporter; |
85 | 94 |
| 95 InterceptorData get _interceptorData => _closedWorld.interceptorData; |
| 96 |
86 js.Expression constantListGenerator(js.Expression array) { | 97 js.Expression constantListGenerator(js.Expression array) { |
87 // TODO(floitsch): remove hard-coded name. | 98 // TODO(floitsch): remove hard-coded name. |
88 return js.js('makeConstList(#)', [array]); | 99 return js.js('makeConstList(#)', [array]); |
89 } | 100 } |
90 | 101 |
91 js.Expression generateEmbeddedGlobalAccess(String global) { | 102 js.Expression generateEmbeddedGlobalAccess(String global) { |
92 return js.js(generateEmbeddedGlobalAccessString(global)); | 103 return js.js(generateEmbeddedGlobalAccessString(global)); |
93 } | 104 } |
94 | 105 |
95 String generateEmbeddedGlobalAccessString(String global) { | 106 String generateEmbeddedGlobalAccessString(String global) { |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 // data. | 389 // data. |
379 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 390 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
380 "needed for a given deferred library import."; | 391 "needed for a given deferred library import."; |
381 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 392 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
382 compiler.outputProvider( | 393 compiler.outputProvider( |
383 compiler.options.deferredMapUri.path, '', OutputType.info) | 394 compiler.options.deferredMapUri.path, '', OutputType.info) |
384 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 395 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
385 ..close(); | 396 ..close(); |
386 } | 397 } |
387 } | 398 } |
OLD | NEW |