| 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 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 assert(invariant(member, previousName == memberName, | 1672 assert(invariant(member, previousName == memberName, |
| 1673 message: '$previousName != ${memberName}')); | 1673 message: '$previousName != ${memberName}')); |
| 1674 } | 1674 } |
| 1675 | 1675 |
| 1676 /// Returns `true` if fields added. | 1676 /// Returns `true` if fields added. |
| 1677 bool emitClassFields(ClassElement classElement, | 1677 bool emitClassFields(ClassElement classElement, |
| 1678 ClassBuilder builder, | 1678 ClassBuilder builder, |
| 1679 String superName, | 1679 String superName, |
| 1680 { bool classIsNative: false, | 1680 { bool classIsNative: false, |
| 1681 bool emitStatics: false }) { | 1681 bool emitStatics: false }) { |
| 1682 assert(superName != null); | |
| 1683 String separator = ''; | |
| 1684 String nativeName = namer.getPrimitiveInterceptorRuntimeName(classElement); | |
| 1685 StringBuffer buffer = new StringBuffer(); | 1682 StringBuffer buffer = new StringBuffer(); |
| 1686 if (!emitStatics) { | 1683 if (emitStatics) { |
| 1684 assert(invariant(classElement, superName == null, message: superName)); |
| 1685 } else { |
| 1686 assert(invariant(classElement, superName != null)); |
| 1687 String nativeName = |
| 1688 namer.getPrimitiveInterceptorRuntimeName(classElement); |
| 1687 if (nativeName != null) { | 1689 if (nativeName != null) { |
| 1688 buffer.write('$nativeName/'); | 1690 buffer.write('$nativeName/'); |
| 1689 } | 1691 } |
| 1690 buffer.write('$superName;'); | 1692 buffer.write('$superName;'); |
| 1691 } | 1693 } |
| 1692 int bufferClassLength = buffer.length; | 1694 int bufferClassLength = buffer.length; |
| 1693 | 1695 |
| 1696 String separator = ''; |
| 1697 |
| 1694 var fieldMetadata = []; | 1698 var fieldMetadata = []; |
| 1695 bool hasMetadata = false; | 1699 bool hasMetadata = false; |
| 1696 | 1700 |
| 1697 visitClassFields(classElement, emitStatics, | 1701 visitClassFields(classElement, emitStatics, |
| 1698 (Element member, | 1702 (Element member, |
| 1699 String name, | 1703 String name, |
| 1700 String accessorName, | 1704 String accessorName, |
| 1701 bool needsGetter, | 1705 bool needsGetter, |
| 1702 bool needsSetter, | 1706 bool needsSetter, |
| 1703 bool needsCheckedSetter) { | 1707 bool needsCheckedSetter) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1826 String mixinName = namer.getName(computeMixinClass(classElement)); | 1830 String mixinName = namer.getName(computeMixinClass(classElement)); |
| 1827 superName = '$superName+$mixinName'; | 1831 superName = '$superName+$mixinName'; |
| 1828 needsMixinSupport = true; | 1832 needsMixinSupport = true; |
| 1829 } | 1833 } |
| 1830 | 1834 |
| 1831 ClassBuilder builder = new ClassBuilder(); | 1835 ClassBuilder builder = new ClassBuilder(); |
| 1832 emitClassConstructor(classElement, builder); | 1836 emitClassConstructor(classElement, builder); |
| 1833 emitSuper(superName, builder); | 1837 emitSuper(superName, builder); |
| 1834 emitRuntimeName(runtimeName, builder); | 1838 emitRuntimeName(runtimeName, builder); |
| 1835 emitClassFields(classElement, builder, superName); | 1839 emitClassFields(classElement, builder, superName); |
| 1836 var metadata = buildMetadataFunction(classElement); | |
| 1837 if (metadata != null) { | |
| 1838 builder.addProperty("@", metadata); | |
| 1839 } | |
| 1840 emitClassGettersSetters(classElement, builder); | 1840 emitClassGettersSetters(classElement, builder); |
| 1841 if (!classElement.isMixinApplication) { | 1841 if (!classElement.isMixinApplication) { |
| 1842 emitInstanceMembers(classElement, builder); | 1842 emitInstanceMembers(classElement, builder); |
| 1843 } | 1843 } |
| 1844 emitIsTests(classElement, builder); | 1844 emitIsTests(classElement, builder); |
| 1845 | 1845 |
| 1846 emitClassBuilderWithReflectionData( |
| 1847 className, classElement, builder, buffer); |
| 1848 } |
| 1849 |
| 1850 void emitClassBuilderWithReflectionData(String className, |
| 1851 ClassElement classElement, |
| 1852 ClassBuilder builder, |
| 1853 CodeBuffer buffer) { |
| 1854 var metadata = buildMetadataFunction(classElement); |
| 1855 if (metadata != null) { |
| 1856 builder.addProperty("@", metadata); |
| 1857 } |
| 1858 |
| 1846 List<CodeBuffer> classBuffers = elementBuffers[classElement]; | 1859 List<CodeBuffer> classBuffers = elementBuffers[classElement]; |
| 1847 if (classBuffers == null) { | 1860 if (classBuffers == null) { |
| 1848 classBuffers = []; | 1861 classBuffers = []; |
| 1849 } else { | 1862 } else { |
| 1850 elementBuffers.remove(classElement); | 1863 elementBuffers.remove(classElement); |
| 1851 } | 1864 } |
| 1852 CodeBuffer statics = new CodeBuffer(); | 1865 CodeBuffer statics = new CodeBuffer(); |
| 1853 statics.write('{$n'); | 1866 statics.write('{$n'); |
| 1854 bool hasStatics = false; | 1867 bool hasStatics = false; |
| 1855 ClassBuilder staticsBuilder = new ClassBuilder(); | 1868 ClassBuilder staticsBuilder = new ClassBuilder(); |
| 1856 if (emitClassFields( | 1869 if (emitClassFields( |
| 1857 classElement, staticsBuilder, superName, emitStatics: true)) { | 1870 classElement, staticsBuilder, null, emitStatics: true)) { |
| 1858 hasStatics = true; | 1871 hasStatics = true; |
| 1859 statics.write('"":$_'); | 1872 statics.write('"":$_'); |
| 1860 statics.write( | 1873 statics.write( |
| 1861 jsAst.prettyPrint(staticsBuilder.properties.single.value, compiler)); | 1874 jsAst.prettyPrint(staticsBuilder.properties.single.value, compiler)); |
| 1862 statics.write(',$n'); | 1875 statics.write(',$n'); |
| 1863 } | 1876 } |
| 1864 for (CodeBuffer classBuffer in classBuffers) { | 1877 for (CodeBuffer classBuffer in classBuffers) { |
| 1865 // TODO(ahe): What about deferred? | 1878 // TODO(ahe): What about deferred? |
| 1866 if (classBuffer != null) { | 1879 if (classBuffer != null) { |
| 1867 hasStatics = true; | 1880 hasStatics = true; |
| (...skipping 2026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3894 | 3907 |
| 3895 const String HOOKS_API_USAGE = """ | 3908 const String HOOKS_API_USAGE = """ |
| 3896 // The code supports the following hooks: | 3909 // The code supports the following hooks: |
| 3897 // dartPrint(message) - if this function is defined it is called | 3910 // dartPrint(message) - if this function is defined it is called |
| 3898 // instead of the Dart [print] method. | 3911 // instead of the Dart [print] method. |
| 3899 // dartMainRunner(main) - if this function is defined, the Dart [main] | 3912 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 3900 // method will not be invoked directly. | 3913 // method will not be invoked directly. |
| 3901 // Instead, a closure that will invoke [main] is | 3914 // Instead, a closure that will invoke [main] is |
| 3902 // passed to [dartMainRunner]. | 3915 // passed to [dartMainRunner]. |
| 3903 """; | 3916 """; |
| OLD | NEW |