| 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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 } | 626 } |
| 627 | 627 |
| 628 /// Annotated name for [method] encoding arity and named parameters. | 628 /// Annotated name for [method] encoding arity and named parameters. |
| 629 jsAst.Name instanceMethodName(FunctionElement method) { | 629 jsAst.Name instanceMethodName(FunctionElement method) { |
| 630 if (method.isGenerativeConstructorBody) { | 630 if (method.isGenerativeConstructorBody) { |
| 631 return constructorBodyName(method); | 631 return constructorBodyName(method); |
| 632 } | 632 } |
| 633 return invocationName(new Selector.fromElement(method)); | 633 return invocationName(new Selector.fromElement(method)); |
| 634 } | 634 } |
| 635 | 635 |
| 636 String _jsNameHelper(Element e) { |
| 637 if (e.jsInteropName != null && e.jsInteropName.isNotEmpty) |
| 638 return e.jsInteropName; |
| 639 return e.isLibrary ? 'self' : e.name; |
| 640 } |
| 641 |
| 642 String fixedBackendPath(Element element) { |
| 643 if (!element.isJsInterop) return null; |
| 644 if (element.isInstanceMember) return 'this'; |
| 645 if (element.isConstructor) return fixedBackendPath(element.enclosingClass); |
| 646 if (element.isLibrary) return 'self'; |
| 647 var sb = new StringBuffer(); |
| 648 sb..write(_jsNameHelper(element.library)); |
| 649 |
| 650 if (element.enclosingClass != null && element.enclosingClass != element) { |
| 651 sb..write('.')..write(_jsNameHelper(element.enclosingClass)); |
| 652 } |
| 653 return sb.toString(); |
| 654 } |
| 655 |
| 636 /// Returns the annotated name for a variant of `call`. | 656 /// Returns the annotated name for a variant of `call`. |
| 637 /// The result has the form: | 657 /// The result has the form: |
| 638 /// | 658 /// |
| 639 /// call$<N>$namedParam1...$namedParam<M> | 659 /// call$<N>$namedParam1...$namedParam<M> |
| 640 /// | 660 /// |
| 641 /// This name cannot be minified because it is generated by string | 661 /// This name cannot be minified because it is generated by string |
| 642 /// concatenation at runtime, by applyFunction in js_helper.dart. | 662 /// concatenation at runtime, by applyFunction in js_helper.dart. |
| 643 jsAst.Name deriveCallMethodName(List<String> suffix) { | 663 jsAst.Name deriveCallMethodName(List<String> suffix) { |
| 644 // TODO(asgerf): Avoid clashes when named parameters contain $ symbols. | 664 // TODO(asgerf): Avoid clashes when named parameters contain $ symbols. |
| 645 return new StringBackedName('$callPrefix\$${suffix.join(r'$')}'); | 665 return new StringBackedName('$callPrefix\$${suffix.join(r'$')}'); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 | 777 |
| 758 /** | 778 /** |
| 759 * Returns the JavaScript property name used to store an instance field. | 779 * Returns the JavaScript property name used to store an instance field. |
| 760 */ | 780 */ |
| 761 jsAst.Name instanceFieldPropertyName(FieldElement element) { | 781 jsAst.Name instanceFieldPropertyName(FieldElement element) { |
| 762 ClassElement enclosingClass = element.enclosingClass; | 782 ClassElement enclosingClass = element.enclosingClass; |
| 763 | 783 |
| 764 if (element.hasFixedBackendName) { | 784 if (element.hasFixedBackendName) { |
| 765 // Certain native fields must be given a specific name. Native names must | 785 // Certain native fields must be given a specific name. Native names must |
| 766 // not contain '$'. We rely on this to avoid clashes. | 786 // not contain '$'. We rely on this to avoid clashes. |
| 787 // TODO(jacobr): we need to relax this constraint. |
| 767 assert(enclosingClass.isNative && | 788 assert(enclosingClass.isNative && |
| 768 !element.fixedBackendName.contains(r'$')); | 789 !element.fixedBackendName.contains(r'$')); |
| 769 | 790 |
| 770 return new StringBackedName(element.fixedBackendName); | 791 return new StringBackedName(element.fixedBackendName); |
| 771 } | 792 } |
| 772 | 793 |
| 773 // Instances of BoxFieldElement are special. They are already created with | 794 // Instances of BoxFieldElement are special. They are already created with |
| 774 // a unique and safe name. However, as boxes are not really instances of | 795 // a unique and safe name. However, as boxes are not really instances of |
| 775 // classes, the usual naming scheme that tries to avoid name clashes with | 796 // classes, the usual naming scheme that tries to avoid name clashes with |
| 776 // super classes does not apply. We still do not mark the name as a | 797 // super classes does not apply. We still do not mark the name as a |
| (...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1982 } | 2003 } |
| 1983 } | 2004 } |
| 1984 } | 2005 } |
| 1985 } | 2006 } |
| 1986 | 2007 |
| 1987 enum NamingScope { | 2008 enum NamingScope { |
| 1988 global, | 2009 global, |
| 1989 instance, | 2010 instance, |
| 1990 constant | 2011 constant |
| 1991 } | 2012 } |
| OLD | NEW |