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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 if (selector.isGetter || selector.isSetter) root = '$root\$'; | 718 if (selector.isGetter || selector.isSetter) root = '$root\$'; |
719 return getMappedGlobalName(root, ensureSafe: false); | 719 return getMappedGlobalName(root, ensureSafe: false); |
720 } else { | 720 } else { |
721 String suffix = getInterceptorSuffix(classes); | 721 String suffix = getInterceptorSuffix(classes); |
722 return getMappedGlobalName("$root\$$suffix", ensureSafe: false); | 722 return getMappedGlobalName("$root\$$suffix", ensureSafe: false); |
723 } | 723 } |
724 } | 724 } |
725 | 725 |
726 /// Returns the runtime name for [element]. The result is not safe as an id. | 726 /// Returns the runtime name for [element]. The result is not safe as an id. |
727 String getRuntimeTypeName(Element element) { | 727 String getRuntimeTypeName(Element element) { |
728 if (identical(element, compiler.dynamicClass)) return 'dynamic'; | 728 if (element == null) return 'dynamic'; |
729 return getNameForRti(element); | 729 return getNameForRti(element); |
730 } | 730 } |
731 | 731 |
732 /** | 732 /** |
733 * Returns a preferred JS-id for the given element. The returned id is | 733 * Returns a preferred JS-id for the given element. The returned id is |
734 * guaranteed to be a valid JS-id. Globals and static fields are furthermore | 734 * guaranteed to be a valid JS-id. Globals and static fields are furthermore |
735 * guaranteed to be unique. | 735 * guaranteed to be unique. |
736 * | 736 * |
737 * For accessing statics consider calling [elementAccess] instead. | 737 * For accessing statics consider calling [elementAccess] instead. |
738 */ | 738 */ |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 String getFunctionTypeName(FunctionType functionType) { | 903 String getFunctionTypeName(FunctionType functionType) { |
904 return functionTypeNameMap.putIfAbsent(functionType, () { | 904 return functionTypeNameMap.putIfAbsent(functionType, () { |
905 String proposedName = functionTypeNamer.computeName(functionType); | 905 String proposedName = functionTypeNamer.computeName(functionType); |
906 String freshName = getFreshName(proposedName, usedInstanceNames, | 906 String freshName = getFreshName(proposedName, usedInstanceNames, |
907 suggestedInstanceNames, ensureSafe: true); | 907 suggestedInstanceNames, ensureSafe: true); |
908 return freshName; | 908 return freshName; |
909 }); | 909 }); |
910 } | 910 } |
911 | 911 |
912 String operatorIsType(DartType type) { | 912 String operatorIsType(DartType type) { |
913 if (type.kind == TypeKind.FUNCTION) { | 913 if (type.isFunctionType) { |
914 // TODO(erikcorry): Reduce from $isx to ix when we are minifying. | 914 // TODO(erikcorry): Reduce from $isx to ix when we are minifying. |
915 return '${operatorIsPrefix()}_${getFunctionTypeName(type)}'; | 915 return '${operatorIsPrefix()}_${getFunctionTypeName(type)}'; |
916 } | 916 } |
917 return operatorIs(type.element); | 917 return operatorIs(type.element); |
918 } | 918 } |
919 | 919 |
920 String operatorIs(Element element) { | 920 String operatorIs(Element element) { |
921 // TODO(erikcorry): Reduce from $isx to ix when we are minifying. | 921 // TODO(erikcorry): Reduce from $isx to ix when we are minifying. |
922 return '${operatorIsPrefix()}${getRuntimeTypeName(element)}'; | 922 return '${operatorIsPrefix()}${getRuntimeTypeName(element)}'; |
923 } | 923 } |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 if (!first) { | 1378 if (!first) { |
1379 sb.write('_'); | 1379 sb.write('_'); |
1380 } | 1380 } |
1381 sb.write('_'); | 1381 sb.write('_'); |
1382 visit(link.head); | 1382 visit(link.head); |
1383 first = true; | 1383 first = true; |
1384 } | 1384 } |
1385 } | 1385 } |
1386 } | 1386 } |
1387 } | 1387 } |
OLD | NEW |