| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.new_js_emitter.emitter; | 5 library dart2js.new_js_emitter.emitter; |
| 6 | 6 |
| 7 import '../model.dart'; | 7 import '../model.dart'; |
| 8 import 'model_emitter.dart'; | 8 import 'model_emitter.dart'; |
| 9 import '../../common.dart'; | 9 import '../../common.dart'; |
| 10 import '../../js/js.dart' as js; | 10 import '../../js/js.dart' as js; |
| 11 | 11 |
| 12 import '../../constants/values.dart' show PrimitiveConstantValue; | |
| 13 import '../../tree/tree.dart' show DartString; | |
| 14 | |
| 15 import '../../js_backend/js_backend.dart' show Namer, JavaScriptBackend; | 12 import '../../js_backend/js_backend.dart' show Namer, JavaScriptBackend; |
| 16 import '../../js_emitter/js_emitter.dart' as emitterTask show | 13 import '../../js_emitter/js_emitter.dart' as emitterTask show |
| 17 CodeEmitterTask, | 14 CodeEmitterTask, |
| 18 Emitter; | 15 Emitter; |
| 19 | 16 |
| 20 class Emitter implements emitterTask.Emitter { | 17 class Emitter implements emitterTask.Emitter { |
| 21 final Compiler _compiler; | 18 final Compiler _compiler; |
| 22 final Namer namer; | 19 final Namer namer; |
| 20 final ModelEmitter _emitter; |
| 23 | 21 |
| 24 Emitter(this._compiler, this.namer); | 22 Emitter(Compiler compiler, Namer namer) |
| 23 : this._compiler = compiler, |
| 24 this.namer = namer, |
| 25 _emitter = new ModelEmitter(compiler, namer); |
| 25 | 26 |
| 26 void emitProgram(Program program) { | 27 void emitProgram(Program program) { |
| 27 new ModelEmitter(_compiler).emitProgram(program); | 28 _emitter.emitProgram(program); |
| 28 } | 29 } |
| 29 | 30 |
| 30 // TODO(floitsch): copied from OldEmitter. Adjust or share. | 31 // TODO(floitsch): copied from OldEmitter. Adjust or share. |
| 31 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) { | 32 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) { |
| 32 if (constant.isFunction) return true; // Already emitted. | 33 if (constant.isFunction) return true; // Already emitted. |
| 33 if (constant.isPrimitive) return true; // Inlined. | 34 if (constant.isPrimitive) return true; // Inlined. |
| 34 if (constant.isDummy) return true; // Inlined. | 35 if (constant.isDummy) return true; // Inlined. |
| 35 // The name is null when the constant is already a JS constant. | 36 // The name is null when the constant is already a JS constant. |
| 36 // TODO(floitsch): every constant should be registered, so that we can | 37 // TODO(floitsch): every constant should be registered, so that we can |
| 37 // share the ones that take up too much space (like some strings). | 38 // share the ones that take up too much space (like some strings). |
| (...skipping 23 matching lines...) Expand all Loading... |
| 61 // name) which is unique. | 62 // name) which is unique. |
| 62 return namer.constantName(a).compareTo(namer.constantName(b)); | 63 return namer.constantName(a).compareTo(namer.constantName(b)); |
| 63 } | 64 } |
| 64 | 65 |
| 65 js.Expression generateEmbeddedGlobalAccess(String global) { | 66 js.Expression generateEmbeddedGlobalAccess(String global) { |
| 66 // TODO(floitsch): We should not use "init" for globals. | 67 // TODO(floitsch): We should not use "init" for globals. |
| 67 return js.string("init.$global"); | 68 return js.string("init.$global"); |
| 68 } | 69 } |
| 69 | 70 |
| 70 js.Expression constantReference(ConstantValue value) { | 71 js.Expression constantReference(ConstantValue value) { |
| 71 if (!value.isPrimitive) return js.string("<<unimplemented>>"); | 72 return _emitter.constantEmitter.reference(value); |
| 72 PrimitiveConstantValue constant = value; | |
| 73 if (constant.isBool) return new js.LiteralBool(constant.isTrue); | |
| 74 if (constant.isString) { | |
| 75 DartString dartString = constant.primitiveValue; | |
| 76 return js.string(dartString.slowToString()); | |
| 77 } | |
| 78 if (constant.isNum) return js.number(constant.primitiveValue); | |
| 79 if (constant.isNull) return new js.LiteralNull(); | |
| 80 return js.string("<<unimplemented>>"); | |
| 81 } | 73 } |
| 82 | 74 |
| 83 void invalidateCaches() {} | 75 void invalidateCaches() {} |
| 84 } | 76 } |
| OLD | NEW |