OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
6 | 6 |
7 const USE_LAZY_EMITTER = const bool.fromEnvironment("dart2js.use.lazy.emitter"); | 7 const USE_LAZY_EMITTER = const bool.fromEnvironment("dart2js.use.lazy.emitter"); |
8 | 8 |
9 /** | 9 /** |
10 * Generates the code for all used classes in the program. Static fields (even | 10 * Generates the code for all used classes in the program. Static fields (even |
11 * in classes) are ignored, since they can be treated as non-class elements. | 11 * in classes) are ignored, since they can be treated as non-class elements. |
12 * | 12 * |
13 * The code for the containing (used) methods must exist in the `universe`. | 13 * The code for the containing (used) methods must exist in the `universe`. |
14 */ | 14 */ |
15 class CodeEmitterTask extends CompilerTask { | 15 class CodeEmitterTask extends CompilerTask { |
16 // TODO(floitsch): the code-emitter task should not need a namer. | 16 // TODO(floitsch): the code-emitter task should not need a namer. |
17 final Namer namer; | 17 final Namer namer; |
18 final TypeTestRegistry typeTestRegistry; | 18 final TypeTestRegistry typeTestRegistry; |
19 NativeEmitter nativeEmitter; | 19 NativeEmitter nativeEmitter; |
20 MetadataCollector metadataCollector; | 20 MetadataCollector metadataCollector; |
21 Emitter emitter; | 21 Emitter emitter; |
| 22 final Compiler compiler; |
22 | 23 |
23 /// Records if a type variable is read dynamically for type tests. | 24 /// Records if a type variable is read dynamically for type tests. |
24 final Set<TypeVariableElement> readTypeVariables = | 25 final Set<TypeVariableElement> readTypeVariables = |
25 new Set<TypeVariableElement>(); | 26 new Set<TypeVariableElement>(); |
26 | 27 |
27 JavaScriptBackend get backend => compiler.backend; | 28 JavaScriptBackend get backend => compiler.backend; |
28 | 29 |
29 @deprecated | 30 @deprecated |
30 // This field should be removed. It's currently only needed for dump-info and | 31 // This field should be removed. It's currently only needed for dump-info and |
31 // tests. | 32 // tests. |
32 // The field is set after the program has been emitted. | 33 // The field is set after the program has been emitted. |
33 /// Contains a list of all classes that are emitted. | 34 /// Contains a list of all classes that are emitted. |
34 Set<ClassElement> neededClasses; | 35 Set<ClassElement> neededClasses; |
35 | 36 |
36 CodeEmitterTask(Compiler compiler, Namer namer, bool generateSourceMap, | 37 CodeEmitterTask(Compiler compiler, Namer namer, bool generateSourceMap, |
37 bool useStartupEmitter) | 38 bool useStartupEmitter) |
38 : super(compiler), | 39 : compiler = compiler, |
39 this.namer = namer, | 40 this.namer = namer, |
40 this.typeTestRegistry = new TypeTestRegistry(compiler) { | 41 this.typeTestRegistry = new TypeTestRegistry(compiler), |
| 42 super(compiler.measurer) { |
41 nativeEmitter = new NativeEmitter(this); | 43 nativeEmitter = new NativeEmitter(this); |
42 if (USE_LAZY_EMITTER) { | 44 if (USE_LAZY_EMITTER) { |
43 emitter = new lazy_js_emitter.Emitter(compiler, namer, nativeEmitter); | 45 emitter = new lazy_js_emitter.Emitter(compiler, namer, nativeEmitter); |
44 } else if (useStartupEmitter) { | 46 } else if (useStartupEmitter) { |
45 emitter = new startup_js_emitter.Emitter( | 47 emitter = new startup_js_emitter.Emitter( |
46 compiler, namer, nativeEmitter, generateSourceMap); | 48 compiler, namer, nativeEmitter, generateSourceMap); |
47 } else { | 49 } else { |
48 emitter = | 50 emitter = |
49 new full_js_emitter.Emitter(compiler, namer, generateSourceMap, this); | 51 new full_js_emitter.Emitter(compiler, namer, generateSourceMap, this); |
50 } | 52 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); | 203 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); |
202 | 204 |
203 /// Returns the JS code for accessing the given [constant]. | 205 /// Returns the JS code for accessing the given [constant]. |
204 jsAst.Expression constantReference(ConstantValue constant); | 206 jsAst.Expression constantReference(ConstantValue constant); |
205 | 207 |
206 /// Returns the JS template for the given [builtin]. | 208 /// Returns the JS template for the given [builtin]. |
207 jsAst.Template templateForBuiltin(JsBuiltin builtin); | 209 jsAst.Template templateForBuiltin(JsBuiltin builtin); |
208 | 210 |
209 void invalidateCaches(); | 211 void invalidateCaches(); |
210 } | 212 } |
OLD | NEW |