OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
9 * | 9 * |
10 * Names are generated through three stages: | 10 * Names are generated through three stages: |
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 void visitConstructed(ConstructedConstantValue constant, [_]) { | 1703 void visitConstructed(ConstructedConstantValue constant, [_]) { |
1704 addRoot(constant.type.element.name); | 1704 addRoot(constant.type.element.name); |
1705 for (ConstantValue value in constant.fields.values) { | 1705 for (ConstantValue value in constant.fields.values) { |
1706 _visit(value); | 1706 _visit(value); |
1707 if (failed) return; | 1707 if (failed) return; |
1708 } | 1708 } |
1709 } | 1709 } |
1710 | 1710 |
1711 @override | 1711 @override |
1712 void visitType(TypeConstantValue constant, [_]) { | 1712 void visitType(TypeConstantValue constant, [_]) { |
1713 // Generates something like 'Type_String_k8F', using the simple name of the | |
1714 // type and a hash to disambiguate the same name in different libraries. | |
1715 addRoot('Type'); | 1713 addRoot('Type'); |
1716 DartType type = constant.representedType; | 1714 DartType type = constant.representedType; |
1717 String simpleName = type.element.name; | 1715 JavaScriptBackend backend = compiler.backend; |
1718 addIdentifier(simpleName); | 1716 String name = backend.rti.getTypeRepresentationForTypeConstant(type); |
1719 add(getHashTag(constant, 3)); | 1717 addIdentifier(name); |
1720 } | 1718 } |
1721 | 1719 |
1722 @override | 1720 @override |
1723 void visitInterceptor(InterceptorConstantValue constant, [_]) { | 1721 void visitInterceptor(InterceptorConstantValue constant, [_]) { |
1724 addRoot(constant.dispatchedType.element.name); | 1722 addRoot(constant.dispatchedType.element.name); |
1725 add('methods'); | 1723 add('methods'); |
1726 } | 1724 } |
1727 | 1725 |
1728 @override | 1726 @override |
1729 void visitSynthetic(SyntheticConstantValue constant, [_]) { | 1727 void visitSynthetic(SyntheticConstantValue constant, [_]) { |
1730 switch (constant.kind) { | 1728 switch (constant.kind) { |
1731 case SyntheticConstantKind.DUMMY_INTERCEPTOR: | 1729 case SyntheticConstantKind.DUMMY_INTERCEPTOR: |
1732 add('dummy_receiver'); | 1730 add('dummy_receiver'); |
1733 break; | 1731 break; |
1734 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: | 1732 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: |
1735 // Omit. These are opaque deferred indexes with nothing helpful to add. | 1733 add('type_variable_reference'); |
1736 break; | 1734 break; |
1737 case SyntheticConstantKind.NAME: | 1735 case SyntheticConstantKind.NAME: |
1738 add('name'); | 1736 add('name'); |
1739 break; | 1737 break; |
1740 default: | 1738 default: |
1741 compiler.internalError(compiler.currentElement, | 1739 compiler.internalError(compiler.currentElement, |
1742 "Unexpected SyntheticConstantValue"); | 1740 "Unexpected SyntheticConstantValue"); |
1743 } | 1741 } |
1744 } | 1742 } |
1745 | 1743 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1824 for (ConstantValue value in constant.fields.values) { | 1822 for (ConstantValue value in constant.fields.values) { |
1825 hash = _combine(hash, _visit(value)); | 1823 hash = _combine(hash, _visit(value)); |
1826 } | 1824 } |
1827 return hash; | 1825 return hash; |
1828 } | 1826 } |
1829 | 1827 |
1830 @override | 1828 @override |
1831 int visitType(TypeConstantValue constant, [_]) { | 1829 int visitType(TypeConstantValue constant, [_]) { |
1832 DartType type = constant.representedType; | 1830 DartType type = constant.representedType; |
1833 JavaScriptBackend backend = compiler.backend; | 1831 JavaScriptBackend backend = compiler.backend; |
1834 // This name includes the library name and type parameters. | |
1835 String name = backend.rti.getTypeRepresentationForTypeConstant(type); | 1832 String name = backend.rti.getTypeRepresentationForTypeConstant(type); |
1836 return _hashString(4, name); | 1833 return _hashString(4, name); |
1837 } | 1834 } |
1838 | 1835 |
1839 @override | 1836 @override |
1840 int visitInterceptor(InterceptorConstantValue constant, [_]) { | 1837 int visitInterceptor(InterceptorConstantValue constant, [_]) { |
1841 String typeName = constant.dispatchedType.element.name; | 1838 String typeName = constant.dispatchedType.element.name; |
1842 return _hashString(5, typeName); | 1839 return _hashString(5, typeName); |
1843 } | 1840 } |
1844 | 1841 |
1845 @override | 1842 @override |
1846 int visitSynthetic(SyntheticConstantValue constant, [_]) { | 1843 visitSynthetic(SyntheticConstantValue constant, [_]) { |
1847 switch (constant.kind) { | 1844 switch (constant.kind) { |
1848 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: | 1845 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: |
1849 // These contain a deferred opaque index into metadata. There is nothing | 1846 return constant.payload.hashCode; |
1850 // we can access that is stable between compiles. Luckily, since they | |
1851 // resolve to integer indexes, they're always part of a larger constant. | |
1852 return 0; | |
1853 default: | 1847 default: |
1854 compiler.internalError(NO_LOCATION_SPANNABLE, | 1848 compiler.internalError(NO_LOCATION_SPANNABLE, |
1855 'SyntheticConstantValue should never be named and
' | 1849 'SyntheticConstantValue should never be named and
' |
1856 'never be subconstant'); | 1850 'never be subconstant'); |
1857 return 0; | 1851 return null; |
1858 } | 1852 } |
1859 } | 1853 } |
1860 | 1854 |
1861 @override | 1855 @override |
1862 int visitDeferred(DeferredConstantValue constant, [_]) { | 1856 int visitDeferred(DeferredConstantValue constant, [_]) { |
1863 int hash = constant.prefix.hashCode; | 1857 int hash = constant.prefix.hashCode; |
1864 return _combine(hash, _visit(constant.referenced)); | 1858 return _combine(hash, _visit(constant.referenced)); |
1865 } | 1859 } |
1866 | 1860 |
1867 int _hashString(int hash, String s) { | 1861 int _hashString(int hash, String s) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 } | 1982 } |
1989 } | 1983 } |
1990 } | 1984 } |
1991 } | 1985 } |
1992 | 1986 |
1993 enum NamingScope { | 1987 enum NamingScope { |
1994 global, | 1988 global, |
1995 instance, | 1989 instance, |
1996 constant | 1990 constant |
1997 } | 1991 } |
OLD | NEW |