| 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 class Namer implements ClosureNamer { | 10 class Namer implements ClosureNamer { |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 String getNameX(Element element) { | 762 String getNameX(Element element) { |
| 763 if (element.isInstanceMember()) { | 763 if (element.isInstanceMember()) { |
| 764 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY | 764 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY |
| 765 || element.kind == ElementKind.FUNCTION) { | 765 || element.kind == ElementKind.FUNCTION) { |
| 766 return instanceMethodName(element); | 766 return instanceMethodName(element); |
| 767 } else if (element.kind == ElementKind.GETTER) { | 767 } else if (element.kind == ElementKind.GETTER) { |
| 768 return getterName(element); | 768 return getterName(element); |
| 769 } else if (element.kind == ElementKind.SETTER) { | 769 } else if (element.kind == ElementKind.SETTER) { |
| 770 return setterName(element); | 770 return setterName(element); |
| 771 } else if (element.kind == ElementKind.FIELD) { | 771 } else if (element.kind == ElementKind.FIELD) { |
| 772 compiler.internalError( | 772 compiler.internalError(element, |
| 773 'use instanceFieldPropertyName or instanceFieldAccessorName', | 773 'Use instanceFieldPropertyName or instanceFieldAccessorName.'); |
| 774 node: element.parseNode(compiler)); | |
| 775 return null; | 774 return null; |
| 776 } else { | 775 } else { |
| 777 compiler.internalError('getName for bad kind: ${element.kind}', | 776 compiler.internalError(element, |
| 778 node: element.parseNode(compiler)); | 777 'getName for bad kind: ${element.kind}.'); |
| 779 return null; | 778 return null; |
| 780 } | 779 } |
| 781 } else { | 780 } else { |
| 782 // Use declaration element to ensure invariant on [globals]. | 781 // Use declaration element to ensure invariant on [globals]. |
| 783 element = element.declaration; | 782 element = element.declaration; |
| 784 // Dealing with a top-level or static element. | 783 // Dealing with a top-level or static element. |
| 785 String cached = globals[element]; | 784 String cached = globals[element]; |
| 786 if (cached != null) return cached; | 785 if (cached != null) return cached; |
| 787 | 786 |
| 788 String guess = _computeGuess(element); | 787 String guess = _computeGuess(element); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 804 if (Elements.isInstanceField(element)) { | 803 if (Elements.isInstanceField(element)) { |
| 805 fixedName = element.hasFixedBackendName(); | 804 fixedName = element.hasFixedBackendName(); |
| 806 } | 805 } |
| 807 String result = fixedName | 806 String result = fixedName |
| 808 ? guess | 807 ? guess |
| 809 : getFreshName(guess, usedGlobalNames, suggestedGlobalNames, | 808 : getFreshName(guess, usedGlobalNames, suggestedGlobalNames, |
| 810 ensureSafe: true); | 809 ensureSafe: true); |
| 811 globals[element] = result; | 810 globals[element] = result; |
| 812 return result; | 811 return result; |
| 813 } | 812 } |
| 814 compiler.internalError('getName for unknown kind: ${element.kind}', | 813 compiler.internalError(element, |
| 815 node: element.parseNode(compiler)); | 814 'getName for unknown kind: ${element.kind}.'); |
| 816 return null; | 815 return null; |
| 817 } | 816 } |
| 818 } | 817 } |
| 819 | 818 |
| 820 String getNameForRti(Element element) => getNameX(element); | 819 String getNameForRti(Element element) => getNameX(element); |
| 821 | 820 |
| 822 String getNameOfLibrary(LibraryElement library) => getNameX(library); | 821 String getNameOfLibrary(LibraryElement library) => getNameX(library); |
| 823 | 822 |
| 824 String getNameOfClass(ClassElement cls) => getNameX(cls); | 823 String getNameOfClass(ClassElement cls) => getNameX(cls); |
| 825 | 824 |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 String name = backend.rti.getRawTypeRepresentation(type); | 1250 String name = backend.rti.getRawTypeRepresentation(type); |
| 1252 return _hashString(4, name); | 1251 return _hashString(4, name); |
| 1253 } | 1252 } |
| 1254 | 1253 |
| 1255 visitInterceptor(InterceptorConstant constant) { | 1254 visitInterceptor(InterceptorConstant constant) { |
| 1256 String typeName = constant.dispatchedType.element.name; | 1255 String typeName = constant.dispatchedType.element.name; |
| 1257 return _hashString(5, typeName); | 1256 return _hashString(5, typeName); |
| 1258 } | 1257 } |
| 1259 | 1258 |
| 1260 visitDummy(DummyConstant constant) { | 1259 visitDummy(DummyConstant constant) { |
| 1261 compiler.internalError( | 1260 compiler.internalError(NO_LOCATION_SPANNABLE, |
| 1262 'DummyReceiverConstant should never be named and never be subconstant'); | 1261 'DummyReceiverConstant should never be named and never be subconstant'); |
| 1263 } | 1262 } |
| 1264 | 1263 |
| 1265 int _hashString(int hash, String s) { | 1264 int _hashString(int hash, String s) { |
| 1266 int length = s.length; | 1265 int length = s.length; |
| 1267 hash = _combine(hash, length); | 1266 hash = _combine(hash, length); |
| 1268 // Increasing stride is O(log N) on large strings which are unlikely to have | 1267 // Increasing stride is O(log N) on large strings which are unlikely to have |
| 1269 // many collisions. | 1268 // many collisions. |
| 1270 for (int i = 0; i < length; i += 1 + (i >> 2)) { | 1269 for (int i = 0; i < length; i += 1 + (i >> 2)) { |
| 1271 hash = _combine(hash, s.codeUnitAt(i)); | 1270 hash = _combine(hash, s.codeUnitAt(i)); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 if (!first) { | 1385 if (!first) { |
| 1387 sb.write('_'); | 1386 sb.write('_'); |
| 1388 } | 1387 } |
| 1389 sb.write('_'); | 1388 sb.write('_'); |
| 1390 visit(link.head); | 1389 visit(link.head); |
| 1391 first = true; | 1390 first = true; |
| 1392 } | 1391 } |
| 1393 } | 1392 } |
| 1394 } | 1393 } |
| 1395 } | 1394 } |
| OLD | NEW |