Chromium Code Reviews| 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 js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
| 9 * from the given element. | 9 * from the given element. |
| 10 */ | 10 */ |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 * A cache of closures that are used to closurize instance methods | 56 * A cache of closures that are used to closurize instance methods |
| 57 * of interceptors. These closures are dynamically bound to the | 57 * of interceptors. These closures are dynamically bound to the |
| 58 * interceptor instance, and the actual receiver of the method. | 58 * interceptor instance, and the actual receiver of the method. |
| 59 */ | 59 */ |
| 60 final Map<int, String> interceptorClosureCache; | 60 final Map<int, String> interceptorClosureCache; |
| 61 Set<ClassElement> checkedClasses; | 61 Set<ClassElement> checkedClasses; |
| 62 Set<TypedefElement> checkedTypedefs; | 62 Set<TypedefElement> checkedTypedefs; |
| 63 | 63 |
| 64 final bool generateSourceMap; | 64 final bool generateSourceMap; |
| 65 | 65 |
| 66 RuntimeTypeInformation get rti { | |
|
ngeoffray
2012/12/12 12:09:11
I'd rather not have this getter.
karlklose
2012/12/12 14:50:47
Done.
| |
| 67 JavaScriptBackend backend = compiler.backend; | |
| 68 return backend.rti; | |
| 69 } | |
| 70 | |
| 66 CodeEmitterTask(Compiler compiler, Namer namer, this.generateSourceMap) | 71 CodeEmitterTask(Compiler compiler, Namer namer, this.generateSourceMap) |
| 67 : boundClosureBuffer = new CodeBuffer(), | 72 : boundClosureBuffer = new CodeBuffer(), |
| 68 mainBuffer = new CodeBuffer(), | 73 mainBuffer = new CodeBuffer(), |
| 69 this.namer = namer, | 74 this.namer = namer, |
| 70 boundClosureCache = new Map<int, String>(), | 75 boundClosureCache = new Map<int, String>(), |
| 71 interceptorClosureCache = new Map<int, String>(), | 76 interceptorClosureCache = new Map<int, String>(), |
| 72 constantEmitter = new ConstantEmitter(compiler, namer), | 77 constantEmitter = new ConstantEmitter(compiler, namer), |
| 73 super(compiler) { | 78 super(compiler) { |
| 74 nativeEmitter = new NativeEmitter(this); | 79 nativeEmitter = new NativeEmitter(this); |
| 75 } | 80 } |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 // Emit the noSuchMethod handlers on the Object prototype now, | 751 // Emit the noSuchMethod handlers on the Object prototype now, |
| 747 // so that the code in the dynamicFunction helper can find | 752 // so that the code in the dynamicFunction helper can find |
| 748 // them. Note that this helper is invoked before analyzing the | 753 // them. Note that this helper is invoked before analyzing the |
| 749 // full JS script. | 754 // full JS script. |
| 750 if (!nativeEmitter.handleNoSuchMethod) { | 755 if (!nativeEmitter.handleNoSuchMethod) { |
| 751 emitNoSuchMethodHandlers(defineInstanceMember); | 756 emitNoSuchMethodHandlers(defineInstanceMember); |
| 752 } | 757 } |
| 753 } | 758 } |
| 754 } | 759 } |
| 755 | 760 |
| 761 void emitRuntimeClassesAndTests(CodeBuffer buffer) { | |
| 762 TypeChecks typeChecks = rti.computeRequiredChecks(); | |
| 763 // Create an object that holds the class name and the checks for all classes | |
| 764 // that are needed but do not have a JS constructor. | |
|
ngeoffray
2012/12/12 12:09:11
do not -> do not
ngeoffray
2012/12/12 12:09:11
What are those? Please add a comment.
karlklose
2012/12/12 14:50:47
Done.
karlklose
2012/12/12 14:50:47
Done.
| |
| 765 for (ClassElement requiredClass in rti.requiredClasses) { | |
| 766 String holder = namer.isolateAccess(requiredClass); | |
| 767 String name = namer.getName(requiredClass); | |
| 768 buffer.add("$holder = {builtin\$cls: '$name'"); | |
| 769 typeChecks[requiredClass].forEach((check) { | |
| 770 buffer.add(', is\$${namer.getName(check)}: true'); | |
| 771 }); | |
| 772 buffer.add('};\n'); | |
| 773 } | |
| 774 // Add checks to the constructors of instantiated classes. | |
| 775 for (ClassElement cls in typeChecks) { | |
| 776 if (rti.requiredClasses.contains(cls)) { | |
| 777 // We already emitted the is-checks in the object definition for this | |
| 778 // class. | |
| 779 continue; | |
| 780 } | |
| 781 String holder = namer.isolateAccess(cls); | |
| 782 typeChecks[cls].forEach((check) { | |
| 783 buffer.add('$holder.is\$${namer.getName(check)} = true;\n'); | |
| 784 }); | |
| 785 } | |
| 786 } | |
| 787 | |
| 756 /** | 788 /** |
| 757 * Documentation wanted -- johnniwinther | 789 * Documentation wanted -- johnniwinther |
| 758 * | 790 * |
| 759 * Invariant: [classElement] must be a declaration element. | 791 * Invariant: [classElement] must be a declaration element. |
| 760 */ | 792 */ |
| 761 void visitClassFields(ClassElement classElement, | 793 void visitClassFields(ClassElement classElement, |
| 762 void addField(Element member, | 794 void addField(Element member, |
| 763 String name, | 795 String name, |
| 764 String accessorName, | 796 String accessorName, |
| 765 bool needsGetter, | 797 bool needsGetter, |
| (...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1911 mainBuffer.add('var $isolateProperties = $isolatePropertiesName;\n'); | 1943 mainBuffer.add('var $isolateProperties = $isolatePropertiesName;\n'); |
| 1912 emitClasses(mainBuffer); | 1944 emitClasses(mainBuffer); |
| 1913 mainBuffer.add(boundClosureBuffer); | 1945 mainBuffer.add(boundClosureBuffer); |
| 1914 // Clear the buffer, so that we can reuse it for the native classes. | 1946 // Clear the buffer, so that we can reuse it for the native classes. |
| 1915 boundClosureBuffer.clear(); | 1947 boundClosureBuffer.clear(); |
| 1916 emitStaticFunctions(mainBuffer); | 1948 emitStaticFunctions(mainBuffer); |
| 1917 emitStaticFunctionGetters(mainBuffer); | 1949 emitStaticFunctionGetters(mainBuffer); |
| 1918 // We need to finish the classes before we construct compile time | 1950 // We need to finish the classes before we construct compile time |
| 1919 // constants. | 1951 // constants. |
| 1920 emitFinishClassesInvocationIfNecessary(mainBuffer); | 1952 emitFinishClassesInvocationIfNecessary(mainBuffer); |
| 1953 emitRuntimeClassesAndTests(mainBuffer); | |
| 1921 emitCompileTimeConstants(mainBuffer); | 1954 emitCompileTimeConstants(mainBuffer); |
| 1922 // Static field initializations require the classes and compile-time | 1955 // Static field initializations require the classes and compile-time |
| 1923 // constants to be set up. | 1956 // constants to be set up. |
| 1924 emitStaticNonFinalFieldInitializations(mainBuffer); | 1957 emitStaticNonFinalFieldInitializations(mainBuffer); |
| 1925 emitGetInterceptorMethods(mainBuffer); | 1958 emitGetInterceptorMethods(mainBuffer); |
| 1926 emitLazilyInitializedStaticFields(mainBuffer); | 1959 emitLazilyInitializedStaticFields(mainBuffer); |
| 1927 | 1960 |
| 1928 isolateProperties = isolatePropertiesName; | 1961 isolateProperties = isolatePropertiesName; |
| 1929 // The following code should not use the short-hand for the | 1962 // The following code should not use the short-hand for the |
| 1930 // initialStatics. | 1963 // initialStatics. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1974 const String HOOKS_API_USAGE = """ | 2007 const String HOOKS_API_USAGE = """ |
| 1975 // Generated by dart2js, the Dart to JavaScript compiler. | 2008 // Generated by dart2js, the Dart to JavaScript compiler. |
| 1976 // The code supports the following hooks: | 2009 // The code supports the following hooks: |
| 1977 // dartPrint(message) - if this function is defined it is called | 2010 // dartPrint(message) - if this function is defined it is called |
| 1978 // instead of the Dart [print] method. | 2011 // instead of the Dart [print] method. |
| 1979 // dartMainRunner(main) - if this function is defined, the Dart [main] | 2012 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 1980 // method will not be invoked directly. | 2013 // method will not be invoked directly. |
| 1981 // Instead, a closure that will invoke [main] is | 2014 // Instead, a closure that will invoke [main] is |
| 1982 // passed to [dartMainRunner]. | 2015 // passed to [dartMainRunner]. |
| 1983 """; | 2016 """; |
| OLD | NEW |