| 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 library dart2js.js_emitter.code_emitter_task; | 5 library dart2js.js_emitter.code_emitter_task; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart' show JsBuiltin; | 7 import 'package:js_runtime/shared/embedded_names.dart' show JsBuiltin; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/tasks.dart' show CompilerTask; | 10 import '../common/tasks.dart' show CompilerTask; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 * The code for the containing (used) methods must exist in the `universe`. | 35 * The code for the containing (used) methods must exist in the `universe`. |
| 36 */ | 36 */ |
| 37 class CodeEmitterTask extends CompilerTask { | 37 class CodeEmitterTask extends CompilerTask { |
| 38 TypeTestRegistry typeTestRegistry; | 38 TypeTestRegistry typeTestRegistry; |
| 39 NativeEmitter _nativeEmitter; | 39 NativeEmitter _nativeEmitter; |
| 40 MetadataCollector metadataCollector; | 40 MetadataCollector metadataCollector; |
| 41 EmitterFactory _emitterFactory; | 41 EmitterFactory _emitterFactory; |
| 42 Emitter _emitter; | 42 Emitter _emitter; |
| 43 final Compiler compiler; | 43 final Compiler compiler; |
| 44 | 44 |
| 45 /// The [Sorter] use for ordering elements in the generated JavaScript. |
| 46 final Sorter sorter; |
| 47 |
| 45 JavaScriptBackend get backend => compiler.backend; | 48 JavaScriptBackend get backend => compiler.backend; |
| 46 | 49 |
| 47 @deprecated | 50 @deprecated |
| 48 // This field should be removed. It's currently only needed for dump-info and | 51 // This field should be removed. It's currently only needed for dump-info and |
| 49 // tests. | 52 // tests. |
| 50 // The field is set after the program has been emitted. | 53 // The field is set after the program has been emitted. |
| 51 /// Contains a list of all classes that are emitted. | 54 /// Contains a list of all classes that are emitted. |
| 52 Set<ClassEntity> neededClasses; | 55 Set<ClassEntity> neededClasses; |
| 53 | 56 |
| 54 CodeEmitterTask( | 57 CodeEmitterTask( |
| 55 Compiler compiler, bool generateSourceMap, bool useStartupEmitter) | 58 Compiler compiler, bool generateSourceMap, bool useStartupEmitter) |
| 56 : compiler = compiler, | 59 : compiler = compiler, |
| 60 sorter = compiler.backendStrategy.sorter, |
| 57 super(compiler.measurer) { | 61 super(compiler.measurer) { |
| 58 if (USE_LAZY_EMITTER) { | 62 if (USE_LAZY_EMITTER) { |
| 59 _emitterFactory = new lazy_js_emitter.EmitterFactory(); | 63 _emitterFactory = new lazy_js_emitter.EmitterFactory(); |
| 60 } else if (useStartupEmitter) { | 64 } else if (useStartupEmitter) { |
| 61 _emitterFactory = new startup_js_emitter.EmitterFactory( | 65 _emitterFactory = new startup_js_emitter.EmitterFactory( |
| 62 generateSourceMap: generateSourceMap); | 66 generateSourceMap: generateSourceMap); |
| 63 } else { | 67 } else { |
| 64 _emitterFactory = new full_js_emitter.EmitterFactory( | 68 _emitterFactory = new full_js_emitter.EmitterFactory( |
| 65 generateSourceMap: generateSourceMap); | 69 generateSourceMap: generateSourceMap); |
| 66 } | 70 } |
| 67 } | 71 } |
| 68 | 72 |
| 69 NativeEmitter get nativeEmitter { | 73 NativeEmitter get nativeEmitter { |
| 70 assert( | 74 assert( |
| 71 _nativeEmitter != null, | 75 _nativeEmitter != null, |
| 72 failedAt( | 76 failedAt( |
| 73 NO_LOCATION_SPANNABLE, "NativeEmitter has not been created yet.")); | 77 NO_LOCATION_SPANNABLE, "NativeEmitter has not been created yet.")); |
| 74 return _nativeEmitter; | 78 return _nativeEmitter; |
| 75 } | 79 } |
| 76 | 80 |
| 77 Emitter get emitter { | 81 Emitter get emitter { |
| 78 assert(_emitter != null, | 82 assert(_emitter != null, |
| 79 failedAt(NO_LOCATION_SPANNABLE, "Emitter has not been created yet.")); | 83 failedAt(NO_LOCATION_SPANNABLE, "Emitter has not been created yet.")); |
| 80 return _emitter; | 84 return _emitter; |
| 81 } | 85 } |
| 82 | 86 |
| 83 /// Returns the [Sorter] use for ordering elements in the generated | |
| 84 /// JavaScript. | |
| 85 // TODO(johnniwinther): Switch this based on the used entity model. | |
| 86 Sorter get sorter => const ElementSorter(); | |
| 87 | |
| 88 String get name => 'Code emitter'; | 87 String get name => 'Code emitter'; |
| 89 | 88 |
| 90 /// Returns true, if the emitter supports reflection. | 89 /// Returns true, if the emitter supports reflection. |
| 91 bool get supportsReflection => _emitterFactory.supportsReflection; | 90 bool get supportsReflection => _emitterFactory.supportsReflection; |
| 92 | 91 |
| 93 /// Returns the closure expression of a static function. | 92 /// Returns the closure expression of a static function. |
| 94 jsAst.Expression isolateStaticClosureAccess(FunctionEntity element) { | 93 jsAst.Expression isolateStaticClosureAccess(FunctionEntity element) { |
| 95 return emitter.isolateStaticClosureAccess(element); | 94 return emitter.isolateStaticClosureAccess(element); |
| 96 } | 95 } |
| 97 | 96 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 @override | 330 @override |
| 332 jsAst.PropertyAccess interceptorClassAccess(ClassEntity element) { | 331 jsAst.PropertyAccess interceptorClassAccess(ClassEntity element) { |
| 333 return globalPropertyAccessForClass(element); | 332 return globalPropertyAccessForClass(element); |
| 334 } | 333 } |
| 335 | 334 |
| 336 @override | 335 @override |
| 337 jsAst.PropertyAccess typeAccess(Entity element) { | 336 jsAst.PropertyAccess typeAccess(Entity element) { |
| 338 return globalPropertyAccessForType(element); | 337 return globalPropertyAccessForType(element); |
| 339 } | 338 } |
| 340 } | 339 } |
| OLD | NEW |