Chromium Code Reviews| 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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 } | 627 } |
| 628 | 628 |
| 629 /// Annotated name for [method] encoding arity and named parameters. | 629 /// Annotated name for [method] encoding arity and named parameters. |
| 630 jsAst.Name instanceMethodName(FunctionElement method) { | 630 jsAst.Name instanceMethodName(FunctionElement method) { |
| 631 if (method.isGenerativeConstructorBody) { | 631 if (method.isGenerativeConstructorBody) { |
| 632 return constructorBodyName(method); | 632 return constructorBodyName(method); |
| 633 } | 633 } |
| 634 return invocationName(new Selector.fromElement(method)); | 634 return invocationName(new Selector.fromElement(method)); |
| 635 } | 635 } |
| 636 | 636 |
| 637 String _jsNameHelper(Element e) { | |
| 638 if (e.jsInteropName != null && e.jsInteropName.isNotEmpty) | |
| 639 return e.jsInteropName; | |
| 640 return e.isLibrary ? 'self' : e.name; | |
| 641 } | |
| 642 | |
| 643 String fixedBackendPath(Element element) { | |
|
Siggi Cherem (dart-lang)
2015/10/06 22:38:02
+ dartdoc?
Jacob
2015/10/13 01:19:23
Done.
| |
| 644 if (!element.isJsInterop) return null; | |
| 645 if (element.isInstanceMember) return 'this'; | |
| 646 if (element.isConstructor) return fixedBackendPath(element.enclosingClass); | |
| 647 if (element.isLibrary) return 'self'; | |
| 648 var sb = new StringBuffer(); | |
| 649 sb..write(_jsNameHelper(element.library)); | |
| 650 | |
| 651 if (element.enclosingClass != null && element.enclosingClass != element) { | |
| 652 sb..write('.')..write(_jsNameHelper(element.enclosingClass)); | |
| 653 } | |
| 654 return sb.toString(); | |
| 655 } | |
| 656 | |
| 637 /// Returns the annotated name for a variant of `call`. | 657 /// Returns the annotated name for a variant of `call`. |
| 638 /// The result has the form: | 658 /// The result has the form: |
| 639 /// | 659 /// |
| 640 /// call$<N>$namedParam1...$namedParam<M> | 660 /// call$<N>$namedParam1...$namedParam<M> |
| 641 /// | 661 /// |
| 642 /// This name cannot be minified because it is generated by string | 662 /// This name cannot be minified because it is generated by string |
| 643 /// concatenation at runtime, by applyFunction in js_helper.dart. | 663 /// concatenation at runtime, by applyFunction in js_helper.dart. |
| 644 jsAst.Name deriveCallMethodName(List<String> suffix) { | 664 jsAst.Name deriveCallMethodName(List<String> suffix) { |
| 645 // TODO(asgerf): Avoid clashes when named parameters contain $ symbols. | 665 // TODO(asgerf): Avoid clashes when named parameters contain $ symbols. |
| 646 return new StringBackedName('$callPrefix\$${suffix.join(r'$')}'); | 666 return new StringBackedName('$callPrefix\$${suffix.join(r'$')}'); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 | 778 |
| 759 /** | 779 /** |
| 760 * Returns the JavaScript property name used to store an instance field. | 780 * Returns the JavaScript property name used to store an instance field. |
| 761 */ | 781 */ |
| 762 jsAst.Name instanceFieldPropertyName(FieldElement element) { | 782 jsAst.Name instanceFieldPropertyName(FieldElement element) { |
| 763 ClassElement enclosingClass = element.enclosingClass; | 783 ClassElement enclosingClass = element.enclosingClass; |
| 764 | 784 |
| 765 if (element.hasFixedBackendName) { | 785 if (element.hasFixedBackendName) { |
| 766 // Certain native fields must be given a specific name. Native names must | 786 // Certain native fields must be given a specific name. Native names must |
| 767 // not contain '$'. We rely on this to avoid clashes. | 787 // not contain '$'. We rely on this to avoid clashes. |
| 788 // TODO(jacobr): we need to relax this constraint. | |
|
Siggi Cherem (dart-lang)
2015/10/06 22:38:02
please file a bug to refer to it here.
Jacob
2015/10/13 01:19:23
synced with sra and we decided this assert can be
| |
| 768 assert(enclosingClass.isNative && | 789 assert(enclosingClass.isNative && |
| 769 !element.fixedBackendName.contains(r'$')); | 790 !element.fixedBackendName.contains(r'$')); |
| 770 | 791 |
| 771 return new StringBackedName(element.fixedBackendName); | 792 return new StringBackedName(element.fixedBackendName); |
| 772 } | 793 } |
| 773 | 794 |
| 774 // Instances of BoxFieldElement are special. They are already created with | 795 // Instances of BoxFieldElement are special. They are already created with |
| 775 // a unique and safe name. However, as boxes are not really instances of | 796 // a unique and safe name. However, as boxes are not really instances of |
| 776 // classes, the usual naming scheme that tries to avoid name clashes with | 797 // classes, the usual naming scheme that tries to avoid name clashes with |
| 777 // super classes does not apply. We still do not mark the name as a | 798 // super classes does not apply. We still do not mark the name as a |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1993 } | 2014 } |
| 1994 } | 2015 } |
| 1995 } | 2016 } |
| 1996 } | 2017 } |
| 1997 | 2018 |
| 1998 enum NamingScope { | 2019 enum NamingScope { |
| 1999 global, | 2020 global, |
| 2000 instance, | 2021 instance, |
| 2001 constant | 2022 constant |
| 2002 } | 2023 } |
| OLD | NEW |