| 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 OldEmitter oldEmitter; | |
| 22 Emitter emitter; | 21 Emitter emitter; |
| 23 | 22 |
| 24 /// Records if a type variable is read dynamically for type tests. | 23 /// Records if a type variable is read dynamically for type tests. |
| 25 final Set<TypeVariableElement> readTypeVariables = | 24 final Set<TypeVariableElement> readTypeVariables = |
| 26 new Set<TypeVariableElement>(); | 25 new Set<TypeVariableElement>(); |
| 27 | 26 |
| 28 JavaScriptBackend get backend => compiler.backend; | 27 JavaScriptBackend get backend => compiler.backend; |
| 29 | 28 |
| 30 @deprecated | 29 @deprecated |
| 31 // This field should be removed. It's currently only needed for dump-info and | 30 // This field should be removed. It's currently only needed for dump-info and |
| 32 // tests. | 31 // tests. |
| 33 // The field is set after the program has been emitted. | 32 // The field is set after the program has been emitted. |
| 34 /// Contains a list of all classes that are emitted. | 33 /// Contains a list of all classes that are emitted. |
| 35 Set<ClassElement> neededClasses; | 34 Set<ClassElement> neededClasses; |
| 36 | 35 |
| 37 CodeEmitterTask(Compiler compiler, Namer namer, bool generateSourceMap) | 36 CodeEmitterTask(Compiler compiler, Namer namer, bool generateSourceMap) |
| 38 : super(compiler), | 37 : super(compiler), |
| 39 this.namer = namer, | 38 this.namer = namer, |
| 40 this.typeTestRegistry = new TypeTestRegistry(compiler) { | 39 this.typeTestRegistry = new TypeTestRegistry(compiler) { |
| 41 nativeEmitter = new NativeEmitter(this); | 40 nativeEmitter = new NativeEmitter(this); |
| 42 oldEmitter = new OldEmitter(compiler, namer, generateSourceMap, this); | |
| 43 emitter = USE_LAZY_EMITTER | 41 emitter = USE_LAZY_EMITTER |
| 44 ? new lazy_js_emitter.Emitter(compiler, namer, nativeEmitter) | 42 ? new lazy_js_emitter.Emitter(compiler, namer, nativeEmitter) |
| 45 : oldEmitter; | 43 : new OldEmitter(compiler, namer, generateSourceMap, this); |
| 46 metadataCollector = new MetadataCollector(compiler, emitter); | 44 metadataCollector = new MetadataCollector(compiler, emitter); |
| 47 } | 45 } |
| 48 | 46 |
| 49 String get name => 'Code emitter'; | 47 String get name => 'Code emitter'; |
| 50 | 48 |
| 51 /// Returns the closure expression of a static function. | 49 /// Returns the closure expression of a static function. |
| 52 jsAst.Expression isolateStaticClosureAccess(FunctionElement element) { | 50 jsAst.Expression isolateStaticClosureAccess(FunctionElement element) { |
| 53 return emitter.isolateStaticClosureAccess(element); | 51 return emitter.isolateStaticClosureAccess(element); |
| 54 } | 52 } |
| 55 | 53 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); | 183 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant); |
| 186 | 184 |
| 187 /// Returns the JS code for accessing the given [constant]. | 185 /// Returns the JS code for accessing the given [constant]. |
| 188 jsAst.Expression constantReference(ConstantValue constant); | 186 jsAst.Expression constantReference(ConstantValue constant); |
| 189 | 187 |
| 190 /// Returns the JS template for the given [builtin]. | 188 /// Returns the JS template for the given [builtin]. |
| 191 jsAst.Template templateForBuiltin(JsBuiltin builtin); | 189 jsAst.Template templateForBuiltin(JsBuiltin builtin); |
| 192 | 190 |
| 193 void invalidateCaches(); | 191 void invalidateCaches(); |
| 194 } | 192 } |
| OLD | NEW |