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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 part 'deferred_fragment_hash.dart'; | 53 part 'deferred_fragment_hash.dart'; |
54 part 'fragment_emitter.dart'; | 54 part 'fragment_emitter.dart'; |
55 | 55 |
56 class ModelEmitter { | 56 class ModelEmitter { |
57 final Compiler compiler; | 57 final Compiler compiler; |
58 final Namer namer; | 58 final Namer namer; |
59 ConstantEmitter constantEmitter; | 59 ConstantEmitter constantEmitter; |
60 final NativeEmitter nativeEmitter; | 60 final NativeEmitter nativeEmitter; |
61 final bool shouldGenerateSourceMap; | 61 final bool shouldGenerateSourceMap; |
| 62 final InterceptorData _interceptorData; |
62 | 63 |
63 // The full code that is written to each hunk part-file. | 64 // The full code that is written to each hunk part-file. |
64 final Map<Fragment, CodeOutput> outputBuffers = <Fragment, CodeOutput>{}; | 65 final Map<Fragment, CodeOutput> outputBuffers = <Fragment, CodeOutput>{}; |
65 | 66 |
66 JavaScriptBackend get backend => compiler.backend; | 67 JavaScriptBackend get backend => compiler.backend; |
67 | 68 |
68 /// For deferred loading we communicate the initializers via this global var. | 69 /// For deferred loading we communicate the initializers via this global var. |
69 static const String deferredInitializersGlobal = | 70 static const String deferredInitializersGlobal = |
70 r"$__dart_deferred_initializers__"; | 71 r"$__dart_deferred_initializers__"; |
71 | 72 |
72 static const String partExtension = "part"; | 73 static const String partExtension = "part"; |
73 static const String deferredExtension = "part.js"; | 74 static const String deferredExtension = "part.js"; |
74 | 75 |
75 static const String typeNameProperty = r"builtin$cls"; | 76 static const String typeNameProperty = r"builtin$cls"; |
76 | 77 |
77 ModelEmitter(Compiler compiler, Namer namer, this.nativeEmitter, | 78 ModelEmitter(this.compiler, this.namer, this.nativeEmitter, |
78 this.shouldGenerateSourceMap) | 79 this._interceptorData, this.shouldGenerateSourceMap) { |
79 : this.compiler = compiler, | |
80 this.namer = namer { | |
81 this.constantEmitter = new ConstantEmitter( | 80 this.constantEmitter = new ConstantEmitter( |
82 compiler, namer, this.generateConstantReference, constantListGenerator); | 81 compiler, namer, this.generateConstantReference, constantListGenerator); |
83 } | 82 } |
84 | 83 |
85 DiagnosticReporter get reporter => compiler.reporter; | 84 DiagnosticReporter get reporter => compiler.reporter; |
86 | 85 |
87 js.Expression constantListGenerator(js.Expression array) { | 86 js.Expression constantListGenerator(js.Expression array) { |
88 // TODO(floitsch): remove hard-coded name. | 87 // TODO(floitsch): remove hard-coded name. |
89 return js.js('makeConstList(#)', [array]); | 88 return js.js('makeConstList(#)', [array]); |
90 } | 89 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 145 } |
147 return js.js('#.#', | 146 return js.js('#.#', |
148 [namer.globalObjectForConstant(value), namer.constantName(value)]); | 147 [namer.globalObjectForConstant(value), namer.constantName(value)]); |
149 } | 148 } |
150 | 149 |
151 int emitProgram(Program program) { | 150 int emitProgram(Program program) { |
152 MainFragment mainFragment = program.fragments.first; | 151 MainFragment mainFragment = program.fragments.first; |
153 List<DeferredFragment> deferredFragments = | 152 List<DeferredFragment> deferredFragments = |
154 new List<DeferredFragment>.from(program.deferredFragments); | 153 new List<DeferredFragment>.from(program.deferredFragments); |
155 | 154 |
156 FragmentEmitter fragmentEmitter = | 155 FragmentEmitter fragmentEmitter = new FragmentEmitter( |
157 new FragmentEmitter(compiler, namer, backend, constantEmitter, this); | 156 compiler, namer, backend, constantEmitter, this, _interceptorData); |
158 | 157 |
159 Map<DeferredFragment, _DeferredFragmentHash> deferredHashTokens = | 158 Map<DeferredFragment, _DeferredFragmentHash> deferredHashTokens = |
160 new Map<DeferredFragment, _DeferredFragmentHash>(); | 159 new Map<DeferredFragment, _DeferredFragmentHash>(); |
161 for (DeferredFragment fragment in deferredFragments) { | 160 for (DeferredFragment fragment in deferredFragments) { |
162 deferredHashTokens[fragment] = new _DeferredFragmentHash(fragment); | 161 deferredHashTokens[fragment] = new _DeferredFragmentHash(fragment); |
163 } | 162 } |
164 | 163 |
165 js.Statement mainCode = | 164 js.Statement mainCode = |
166 fragmentEmitter.emitMainFragment(program, deferredHashTokens); | 165 fragmentEmitter.emitMainFragment(program, deferredHashTokens); |
167 | 166 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // data. | 378 // data. |
380 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 379 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
381 "needed for a given deferred library import."; | 380 "needed for a given deferred library import."; |
382 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 381 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
383 compiler.outputProvider( | 382 compiler.outputProvider( |
384 compiler.options.deferredMapUri.path, '', OutputType.info) | 383 compiler.options.deferredMapUri.path, '', OutputType.info) |
385 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 384 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
386 ..close(); | 385 ..close(); |
387 } | 386 } |
388 } | 387 } |
OLD | NEW |