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. | |
1713 addRoot('Type'); | 1715 addRoot('Type'); |
1714 DartType type = constant.representedType; | 1716 DartType type = constant.representedType; |
1715 JavaScriptBackend backend = compiler.backend; | 1717 String simpleName = type.element.name; |
1716 String name = backend.rti.getTypeRepresentationForTypeConstant(type); | 1718 addIdentifier(simpleName); |
1717 addIdentifier(name); | 1719 add(getHashTag(constant, 3)); |
1718 } | 1720 } |
1719 | 1721 |
1720 @override | 1722 @override |
1721 void visitInterceptor(InterceptorConstantValue constant, [_]) { | 1723 void visitInterceptor(InterceptorConstantValue constant, [_]) { |
1722 addRoot(constant.dispatchedType.element.name); | 1724 addRoot(constant.dispatchedType.element.name); |
1723 add('methods'); | 1725 add('methods'); |
1724 } | 1726 } |
1725 | 1727 |
1726 @override | 1728 @override |
1727 void visitSynthetic(SyntheticConstantValue constant, [_]) { | 1729 void visitSynthetic(SyntheticConstantValue constant, [_]) { |
1728 switch (constant.kind) { | 1730 switch (constant.kind) { |
1729 case SyntheticConstantKind.DUMMY_INTERCEPTOR: | 1731 case SyntheticConstantKind.DUMMY_INTERCEPTOR: |
1730 add('dummy_receiver'); | 1732 add('dummy_receiver'); |
1731 break; | 1733 break; |
1732 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: | 1734 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: |
1733 add('type_variable_reference'); | 1735 // Omit. These are opaque deferred indexes with nothing helpful to add. |
1734 break; | 1736 break; |
1735 case SyntheticConstantKind.NAME: | 1737 case SyntheticConstantKind.NAME: |
1736 add('name'); | 1738 add('name'); |
1737 break; | 1739 break; |
1738 default: | 1740 default: |
1739 compiler.internalError(compiler.currentElement, | 1741 compiler.internalError(compiler.currentElement, |
1740 "Unexpected SyntheticConstantValue"); | 1742 "Unexpected SyntheticConstantValue"); |
1741 } | 1743 } |
1742 } | 1744 } |
1743 | 1745 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1822 for (ConstantValue value in constant.fields.values) { | 1824 for (ConstantValue value in constant.fields.values) { |
1823 hash = _combine(hash, _visit(value)); | 1825 hash = _combine(hash, _visit(value)); |
1824 } | 1826 } |
1825 return hash; | 1827 return hash; |
1826 } | 1828 } |
1827 | 1829 |
1828 @override | 1830 @override |
1829 int visitType(TypeConstantValue constant, [_]) { | 1831 int visitType(TypeConstantValue constant, [_]) { |
1830 DartType type = constant.representedType; | 1832 DartType type = constant.representedType; |
1831 JavaScriptBackend backend = compiler.backend; | 1833 JavaScriptBackend backend = compiler.backend; |
1834 // This name includes the library name and type parameters. | |
1832 String name = backend.rti.getTypeRepresentationForTypeConstant(type); | 1835 String name = backend.rti.getTypeRepresentationForTypeConstant(type); |
1833 return _hashString(4, name); | 1836 return _hashString(4, name); |
1834 } | 1837 } |
1835 | 1838 |
1836 @override | 1839 @override |
1837 int visitInterceptor(InterceptorConstantValue constant, [_]) { | 1840 int visitInterceptor(InterceptorConstantValue constant, [_]) { |
1838 String typeName = constant.dispatchedType.element.name; | 1841 String typeName = constant.dispatchedType.element.name; |
1839 return _hashString(5, typeName); | 1842 return _hashString(5, typeName); |
1840 } | 1843 } |
1841 | 1844 |
1842 @override | 1845 @override |
1843 visitSynthetic(SyntheticConstantValue constant, [_]) { | 1846 int visitSynthetic(SyntheticConstantValue constant, [_]) { |
Harry Terkelsen
2015/09/23 17:36:25
this would be clearer if it was:
if (constant.kind
sra1
2015/09/23 22:52:05
I'd like to keep it as-is since other visitSynthet
| |
1844 switch (constant.kind) { | 1847 switch (constant.kind) { |
1845 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: | 1848 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: |
1846 return constant.payload.hashCode; | 1849 // These contain a deferred opaque index into metadata. There is nothing |
1850 // we can access that is stable between compiles. Luckily, since they | |
1851 // resolve to integer indexes, they always part of a larger constant. | |
Harry Terkelsen
2015/09/23 17:36:25
nit: they always -> they're always
sra1
2015/09/23 22:52:05
Done.
| |
1852 return 0; | |
1847 default: | 1853 default: |
1848 compiler.internalError(NO_LOCATION_SPANNABLE, | 1854 compiler.internalError(NO_LOCATION_SPANNABLE, |
1849 'SyntheticConstantValue should never be named and ' | 1855 'SyntheticConstantValue should never be named and ' |
1850 'never be subconstant'); | 1856 'never be subconstant'); |
1851 return null; | 1857 return 0; |
1852 } | 1858 } |
1853 } | 1859 } |
1854 | 1860 |
1855 @override | 1861 @override |
1856 int visitDeferred(DeferredConstantValue constant, [_]) { | 1862 int visitDeferred(DeferredConstantValue constant, [_]) { |
1857 int hash = constant.prefix.hashCode; | 1863 int hash = constant.prefix.hashCode; |
1858 return _combine(hash, _visit(constant.referenced)); | 1864 return _combine(hash, _visit(constant.referenced)); |
1859 } | 1865 } |
1860 | 1866 |
1861 int _hashString(int hash, String s) { | 1867 int _hashString(int hash, String s) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1982 } | 1988 } |
1983 } | 1989 } |
1984 } | 1990 } |
1985 } | 1991 } |
1986 | 1992 |
1987 enum NamingScope { | 1993 enum NamingScope { |
1988 global, | 1994 global, |
1989 instance, | 1995 instance, |
1990 constant | 1996 constant |
1991 } | 1997 } |
OLD | NEW |