| 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 | 7 |
| 8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 jsAst.Expression code = backend.generatedCode[element]; | 913 jsAst.Expression code = backend.generatedCode[element]; |
| 914 // The code is null if we ended up not needing the lazily | 914 // The code is null if we ended up not needing the lazily |
| 915 // initialized field after all because of constant folding | 915 // initialized field after all because of constant folding |
| 916 // before code generation. | 916 // before code generation. |
| 917 if (code == null) continue; | 917 if (code == null) continue; |
| 918 // The code only computes the initial value. We build the lazy-check | 918 // The code only computes the initial value. We build the lazy-check |
| 919 // here: | 919 // here: |
| 920 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); | 920 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); |
| 921 // The name is used for error reporting. The 'initial' must be a | 921 // The name is used for error reporting. The 'initial' must be a |
| 922 // closure that constructs the initial value. | 922 // closure that constructs the initial value. |
| 923 jsAst.Expression getter = buildLazyInitializedGetter(element); | 923 jsAst.Expression init = js('#(#,#,#,#,#)', |
| 924 jsAst.Expression init = js('#(#,#,#,#,#,#)', | |
| 925 [js(lazyInitializerName), | 924 [js(lazyInitializerName), |
| 926 js(isolateProperties), | 925 js(isolateProperties), |
| 927 js.string(element.name), | 926 js.string(element.name), |
| 928 js.string(namer.getNameX(element)), | 927 js.string(namer.getNameX(element)), |
| 929 js.string(namer.getLazyInitializerName(element)), | 928 js.string(namer.getLazyInitializerName(element)), |
| 930 code, | 929 code]); |
| 931 getter == null ? [] : [getter]]); | |
| 932 buffer.write(jsAst.prettyPrint(init, compiler, | 930 buffer.write(jsAst.prettyPrint(init, compiler, |
| 933 monitor: compiler.dumpInfoTask)); | 931 monitor: compiler.dumpInfoTask)); |
| 934 buffer.write("$N"); | 932 buffer.write("$N"); |
| 935 } | 933 } |
| 936 } | 934 } |
| 937 } | 935 } |
| 938 | 936 |
| 939 jsAst.Expression buildLazyInitializedGetter(VariableElement element) { | |
| 940 // Nothing to do, the 'lazy' function will create the getter. | |
| 941 return null; | |
| 942 } | |
| 943 | |
| 944 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) { | 937 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) { |
| 945 if (constant.isFunction) return true; // Already emitted. | 938 if (constant.isFunction) return true; // Already emitted. |
| 946 if (constant.isPrimitive) return true; // Inlined. | 939 if (constant.isPrimitive) return true; // Inlined. |
| 947 if (constant.isDummy) return true; // Inlined. | 940 if (constant.isDummy) return true; // Inlined. |
| 948 // The name is null when the constant is already a JS constant. | 941 // The name is null when the constant is already a JS constant. |
| 949 // TODO(floitsch): every constant should be registered, so that we can | 942 // TODO(floitsch): every constant should be registered, so that we can |
| 950 // share the ones that take up too much space (like some strings). | 943 // share the ones that take up too much space (like some strings). |
| 951 if (namer.constantName(constant) == null) return true; | 944 if (namer.constantName(constant) == null) return true; |
| 952 return false; | 945 return false; |
| 953 } | 946 } |
| (...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 1980 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 1988 if (element.isInstanceMember) { | 1981 if (element.isInstanceMember) { |
| 1989 cachedClassBuilders.remove(element.enclosingClass); | 1982 cachedClassBuilders.remove(element.enclosingClass); |
| 1990 | 1983 |
| 1991 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 1984 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 1992 | 1985 |
| 1993 } | 1986 } |
| 1994 } | 1987 } |
| 1995 } | 1988 } |
| 1996 } | 1989 } |
| OLD | NEW |