| 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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 617 |
| 618 /// Annotated name for [method] encoding arity and named parameters. | 618 /// Annotated name for [method] encoding arity and named parameters. |
| 619 jsAst.Name instanceMethodName(FunctionElement method) { | 619 jsAst.Name instanceMethodName(FunctionElement method) { |
| 620 if (method.isGenerativeConstructorBody) { | 620 if (method.isGenerativeConstructorBody) { |
| 621 return constructorBodyName(method); | 621 return constructorBodyName(method); |
| 622 } | 622 } |
| 623 return invocationName(new Selector.fromElement(method)); | 623 return invocationName(new Selector.fromElement(method)); |
| 624 } | 624 } |
| 625 | 625 |
| 626 String _jsNameHelper(Element e) { | 626 String _jsNameHelper(Element e) { |
| 627 String jsInteropName = backend.getJsInteropName(e); | 627 String jsInteropName = backend.nativeData.getJsInteropName(e); |
| 628 if (jsInteropName != null && jsInteropName.isNotEmpty) | 628 if (jsInteropName != null && jsInteropName.isNotEmpty) |
| 629 return jsInteropName; | 629 return jsInteropName; |
| 630 return e.isLibrary ? 'self' : e.name; | 630 return e.isLibrary ? 'self' : e.name; |
| 631 } | 631 } |
| 632 | 632 |
| 633 /// Returns a JavaScript path specifying the context in which | 633 /// Returns a JavaScript path specifying the context in which |
| 634 /// [element.fixedBackendName] should be evaluated. Only applicable for | 634 /// [element.fixedBackendName] should be evaluated. Only applicable for |
| 635 /// elements using typed JavaScript interop. | 635 /// elements using typed JavaScript interop. |
| 636 /// For example: fixedBackendPath for the static method createMap in the | 636 /// For example: fixedBackendPath for the static method createMap in the |
| 637 /// Map class of the goog.map JavaScript library would have path | 637 /// Map class of the goog.map JavaScript library would have path |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 jsAst.Name globalPropertyName(Element element) { | 772 jsAst.Name globalPropertyName(Element element) { |
| 773 return _disambiguateGlobal(element); | 773 return _disambiguateGlobal(element); |
| 774 } | 774 } |
| 775 | 775 |
| 776 /** | 776 /** |
| 777 * Returns the JavaScript property name used to store an instance field. | 777 * Returns the JavaScript property name used to store an instance field. |
| 778 */ | 778 */ |
| 779 jsAst.Name instanceFieldPropertyName(FieldElement element) { | 779 jsAst.Name instanceFieldPropertyName(FieldElement element) { |
| 780 ClassElement enclosingClass = element.enclosingClass; | 780 ClassElement enclosingClass = element.enclosingClass; |
| 781 | 781 |
| 782 if (backend.hasFixedBackendName(element)) { | 782 if (backend.nativeData.hasFixedBackendName(element)) { |
| 783 return new StringBackedName(backend.getFixedBackendName(element)); | 783 return new StringBackedName( |
| 784 backend.nativeData.getFixedBackendName(element)); |
| 784 } | 785 } |
| 785 | 786 |
| 786 // Some elements, like e.g. instances of BoxFieldElement are special. | 787 // Some elements, like e.g. instances of BoxFieldElement are special. |
| 787 // They are created with a unique and safe name for the element model. | 788 // They are created with a unique and safe name for the element model. |
| 788 // While their name is unique, it is not very readable. So we try to | 789 // While their name is unique, it is not very readable. So we try to |
| 789 // preserve the original, proposed name. | 790 // preserve the original, proposed name. |
| 790 // However, as boxes are not really instances of classes, the usual naming | 791 // However, as boxes are not really instances of classes, the usual naming |
| 791 // scheme that tries to avoid name clashes with super classes does not | 792 // scheme that tries to avoid name clashes with super classes does not |
| 792 // apply. So we can directly grab a name. | 793 // apply. So we can directly grab a name. |
| 793 Entity asEntity = element; | 794 Entity asEntity = element; |
| (...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2044 String suggestName(String original) => _suggestedNames[original]; | 2045 String suggestName(String original) => _suggestedNames[original]; |
| 2045 void addSuggestion(String original, String suggestion) { | 2046 void addSuggestion(String original, String suggestion) { |
| 2046 assert(!_suggestedNames.containsKey(original)); | 2047 assert(!_suggestedNames.containsKey(original)); |
| 2047 _suggestedNames[original] = suggestion; | 2048 _suggestedNames[original] = suggestion; |
| 2048 } | 2049 } |
| 2049 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); | 2050 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); |
| 2050 bool isSuggestion(String candidate) { | 2051 bool isSuggestion(String candidate) { |
| 2051 return _suggestedNames.containsValue(candidate); | 2052 return _suggestedNames.containsValue(candidate); |
| 2052 } | 2053 } |
| 2053 } | 2054 } |
| OLD | NEW |