| 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 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 | 578 |
| 579 String _proposeNameForConstructorBody(ConstructorBodyElement method) { | 579 String _proposeNameForConstructorBody(ConstructorBodyElement method) { |
| 580 String name = Elements.reconstructConstructorNameSourceString(method); | 580 String name = Elements.reconstructConstructorNameSourceString(method); |
| 581 // We include the method suffix on constructor bodies. It has no purpose, | 581 // We include the method suffix on constructor bodies. It has no purpose, |
| 582 // but this way it produces the same names as previous versions of the | 582 // but this way it produces the same names as previous versions of the |
| 583 // Namer class did. | 583 // Namer class did. |
| 584 List<String> suffix = callSuffixForSignature(method.functionSignature); | 584 List<String> suffix = callSuffixForSignature(method.functionSignature); |
| 585 return '$name\$${suffix.join(r'$')}'; | 585 return '$name\$${suffix.join(r'$')}'; |
| 586 } | 586 } |
| 587 | 587 |
| 588 /// Name for a constructor body. |
| 589 jsAst.Name constructorBodyName(FunctionElement ctor) { |
| 590 return _disambiguateInternalMember(ctor, |
| 591 () => _proposeNameForConstructorBody(ctor)); |
| 592 } |
| 593 |
| 588 /// Annotated name for [method] encoding arity and named parameters. | 594 /// Annotated name for [method] encoding arity and named parameters. |
| 589 jsAst.Name instanceMethodName(FunctionElement method) { | 595 jsAst.Name instanceMethodName(FunctionElement method) { |
| 590 if (method.isGenerativeConstructorBody) { | 596 if (method.isGenerativeConstructorBody) { |
| 591 return _disambiguateInternalMember(method, | 597 return constructorBodyName(method); |
| 592 () => _proposeNameForConstructorBody(method)); | |
| 593 } | 598 } |
| 594 return invocationName(new Selector.fromElement(method)); | 599 return invocationName(new Selector.fromElement(method)); |
| 595 } | 600 } |
| 596 | 601 |
| 597 /// Annotated name for a public method with the given [originalName] | 602 /// Annotated name for a public method with the given [originalName] |
| 598 /// and [arity] and no named parameters. | 603 /// and [arity] and no named parameters. |
| 599 jsAst.Name publicInstanceMethodNameByArity(String originalName, | 604 jsAst.Name publicInstanceMethodNameByArity(String originalName, |
| 600 int arity) { | 605 int arity) { |
| 601 return invocationName(new Selector.call(originalName, null, arity)); | 606 return invocationName(new Selector.call(originalName, null, arity)); |
| 602 } | 607 } |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 proposedName += r'$' + suffixes.join(r'$'); | 915 proposedName += r'$' + suffixes.join(r'$'); |
| 911 } | 916 } |
| 912 newName = getFreshName(proposedName, | 917 newName = getFreshName(proposedName, |
| 913 usedInstanceNames, suggestedInstanceNames, | 918 usedInstanceNames, suggestedInstanceNames, |
| 914 sanitizeForAnnotations: true); | 919 sanitizeForAnnotations: true); |
| 915 userInstanceMembers[key] = newName; | 920 userInstanceMembers[key] = newName; |
| 916 } | 921 } |
| 917 return newName; | 922 return newName; |
| 918 } | 923 } |
| 919 | 924 |
| 925 /// Returns the disambiguated name for the instance member identified by |
| 926 /// [key]. |
| 927 /// |
| 928 /// When a name for an element is requested by key, it may not be requested |
| 929 /// by element at the same time, as two different names would be returned. |
| 930 /// |
| 931 /// If key has not yet been registered, [proposeName] is used to generate |
| 932 /// a name proposal for the given key. |
| 933 /// |
| 934 /// [key] must not clash with valid instance names. This is typically |
| 935 /// achieved by using at least one character in [key] that is not valid in |
| 936 /// identifiers, for example the @ symbol. |
| 937 jsAst.Name _disambiguateMemberByKey(String key, String proposeName()) { |
| 938 jsAst.Name newName = userInstanceMembers[key]; |
| 939 if (newName == null) { |
| 940 String name = proposeName(); |
| 941 newName = getFreshName(name, |
| 942 usedInstanceNames, suggestedInstanceNames, |
| 943 sanitizeForAnnotations: true); |
| 944 userInstanceMembers[key] = newName; |
| 945 } |
| 946 return newName; |
| 947 } |
| 948 |
| 920 /// Forces the public instance member with [originalName] to have the given | 949 /// Forces the public instance member with [originalName] to have the given |
| 921 /// [disambiguatedName]. | 950 /// [disambiguatedName]. |
| 922 /// | 951 /// |
| 923 /// The [originalName] must not have been disambiguated before, and the | 952 /// The [originalName] must not have been disambiguated before, and the |
| 924 /// [disambiguatedName] must not have been used. | 953 /// [disambiguatedName] must not have been used. |
| 925 /// | 954 /// |
| 926 /// Using [_disambiguateMember] with the given [originalName] and no suffixes | 955 /// Using [_disambiguateMember] with the given [originalName] and no suffixes |
| 927 /// will subsequently return [disambiguatedName]. | 956 /// will subsequently return [disambiguatedName]. |
| 928 void reservePublicMemberName(String originalName, | 957 void reservePublicMemberName(String originalName, |
| 929 String disambiguatedName) { | 958 String disambiguatedName) { |
| (...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 if (!first) { | 2066 if (!first) { |
| 2038 sb.write('_'); | 2067 sb.write('_'); |
| 2039 } | 2068 } |
| 2040 sb.write('_'); | 2069 sb.write('_'); |
| 2041 visit(parameter); | 2070 visit(parameter); |
| 2042 first = true; | 2071 first = true; |
| 2043 } | 2072 } |
| 2044 } | 2073 } |
| 2045 } | 2074 } |
| 2046 } | 2075 } |
| OLD | NEW |