| 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 case 'CALL_CATCH_ALL': return callCatchAllName; | 291 case 'CALL_CATCH_ALL': return callCatchAllName; |
| 292 case 'REFLECTABLE': return reflectableField; | 292 case 'REFLECTABLE': return reflectableField; |
| 293 default: | 293 default: |
| 294 compiler.reportError( | 294 compiler.reportError( |
| 295 node, MessageKind.GENERIC, | 295 node, MessageKind.GENERIC, |
| 296 {'text': 'Error: Namer has no name for "$name".'}); | 296 {'text': 'Error: Namer has no name for "$name".'}); |
| 297 return 'BROKEN'; | 297 return 'BROKEN'; |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 bool isReserved(String name) => name == isolateName; | |
| 302 | |
| 303 String constantName(Constant constant) { | 301 String constantName(Constant constant) { |
| 304 // In the current implementation it doesn't make sense to give names to | 302 // In the current implementation it doesn't make sense to give names to |
| 305 // function constants since the function-implementation itself serves as | 303 // function constants since the function-implementation itself serves as |
| 306 // constant and can be accessed directly. | 304 // constant and can be accessed directly. |
| 307 assert(!constant.isFunction()); | 305 assert(!constant.isFunction()); |
| 308 String result = constantNames[constant]; | 306 String result = constantNames[constant]; |
| 309 if (result == null) { | 307 if (result == null) { |
| 310 String longName = constantLongName(constant); | 308 String longName = constantLongName(constant); |
| 311 result = getFreshName(longName, usedGlobalNames, suggestedGlobalNames, | 309 result = getFreshName(longName, usedGlobalNames, suggestedGlobalNames, |
| 312 ensureSafe: true); | 310 ensureSafe: true); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 String name = getMappedInstanceName(privateName(library, element.name)); | 511 String name = getMappedInstanceName(privateName(library, element.name)); |
| 514 return '$setterPrefix$name'; | 512 return '$setterPrefix$name'; |
| 515 } | 513 } |
| 516 | 514 |
| 517 String setterNameFromAccessorName(String name) { | 515 String setterNameFromAccessorName(String name) { |
| 518 // We dynamically create setters from the field-name. The setter name must | 516 // We dynamically create setters from the field-name. The setter name must |
| 519 // therefore be derived from the instance field-name. | 517 // therefore be derived from the instance field-name. |
| 520 return '$setterPrefix$name'; | 518 return '$setterPrefix$name'; |
| 521 } | 519 } |
| 522 | 520 |
| 523 String publicGetterName(String name) { | |
| 524 // We dynamically create getters from the field-name. The getter name must | |
| 525 // therefore be derived from the instance field-name. | |
| 526 String fieldName = getMappedInstanceName(name); | |
| 527 return '$getterPrefix$fieldName'; | |
| 528 } | |
| 529 | |
| 530 String getterNameFromAccessorName(String name) { | 521 String getterNameFromAccessorName(String name) { |
| 531 // We dynamically create getters from the field-name. The getter name must | 522 // We dynamically create getters from the field-name. The getter name must |
| 532 // therefore be derived from the instance field-name. | 523 // therefore be derived from the instance field-name. |
| 533 return '$getterPrefix$name'; | 524 return '$getterPrefix$name'; |
| 534 } | 525 } |
| 535 | 526 |
| 536 String getterName(Element element) { | 527 String getterName(Element element) { |
| 537 // We dynamically create getters from the field-name. The getter name must | 528 // We dynamically create getters from the field-name. The getter name must |
| 538 // therefore be derived from the instance field-name. | 529 // therefore be derived from the instance field-name. |
| 539 LibraryElement library = element.getLibrary(); | 530 LibraryElement library = element.getLibrary(); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 | 812 |
| 822 String getNameOfField(VariableElement field) => getNameX(field); | 813 String getNameOfField(VariableElement field) => getNameX(field); |
| 823 | 814 |
| 824 // TODO(ahe): Remove this method. Use get getNameOfMember instead. | 815 // TODO(ahe): Remove this method. Use get getNameOfMember instead. |
| 825 String getNameOfInstanceMember(Element member) => getNameX(member); | 816 String getNameOfInstanceMember(Element member) => getNameX(member); |
| 826 | 817 |
| 827 String getNameOfMember(Element member) => getNameX(member); | 818 String getNameOfMember(Element member) => getNameX(member); |
| 828 | 819 |
| 829 String getNameOfGlobalField(VariableElement field) => getNameX(field); | 820 String getNameOfGlobalField(VariableElement field) => getNameX(field); |
| 830 | 821 |
| 831 // TODO(ahe): Remove this method. Use get getNameOfMember instead. | |
| 832 String getNameOfGlobalFunction(FunctionElement element) => getNameX(element); | |
| 833 | |
| 834 /// Returns true if [element] is stored on current isolate ('$'). We intend | 822 /// Returns true if [element] is stored on current isolate ('$'). We intend |
| 835 /// to store only mutable static state in [currentIsolate], constants are | 823 /// to store only mutable static state in [currentIsolate], constants are |
| 836 /// stored in 'C', and functions, accessors, classes, etc. are stored in one | 824 /// stored in 'C', and functions, accessors, classes, etc. are stored in one |
| 837 /// of the other objects in [reservedGlobalObjectNames]. | 825 /// of the other objects in [reservedGlobalObjectNames]. |
| 838 bool isPropertyOfCurrentIsolate(Element element) { | 826 bool isPropertyOfCurrentIsolate(Element element) { |
| 839 // TODO(ahe): Make sure this method's documentation is always true and | 827 // TODO(ahe): Make sure this method's documentation is always true and |
| 840 // remove the word "intend". | 828 // remove the word "intend". |
| 841 return | 829 return |
| 842 // TODO(ahe): Re-write these tests to be positive (so it only returns | 830 // TODO(ahe): Re-write these tests to be positive (so it only returns |
| 843 // true for static/top-level mutable fields). Right now, a number of | 831 // true for static/top-level mutable fields). Right now, a number of |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1388 if (!first) { | 1376 if (!first) { |
| 1389 sb.write('_'); | 1377 sb.write('_'); |
| 1390 } | 1378 } |
| 1391 sb.write('_'); | 1379 sb.write('_'); |
| 1392 visit(link.head); | 1380 visit(link.head); |
| 1393 first = true; | 1381 first = true; |
| 1394 } | 1382 } |
| 1395 } | 1383 } |
| 1396 } | 1384 } |
| 1397 } | 1385 } |
| OLD | NEW |