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 class Namer implements ClosureNamer { | 10 class Namer implements ClosureNamer { |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 } | 435 } |
| 436 | 436 |
| 437 /** | 437 /** |
| 438 * Returns the internal name used for an invocation mirror of this selector. | 438 * Returns the internal name used for an invocation mirror of this selector. |
| 439 */ | 439 */ |
| 440 String invocationMirrorInternalName(Selector selector) | 440 String invocationMirrorInternalName(Selector selector) |
| 441 => invocationName(selector); | 441 => invocationName(selector); |
| 442 | 442 |
| 443 String instanceFieldName(Element element) { | 443 String fieldPropertyName(Element element) { |
|
ngeoffray
2013/11/11 10:31:32
Please add a comment on the difference between fie
sra1
2013/11/14 00:26:31
Done.
| |
| 444 if (element.isInstanceMember()) return instanceFieldPropertyName(element); | |
|
ngeoffray
2013/11/11 10:31:32
Use return ... ? ... : ...;
sra1
2013/11/14 00:26:31
Done.
| |
| 445 return getNameOfField(element); | |
| 446 } | |
| 447 | |
| 448 String fieldAccessorName(Element element) { | |
| 449 if (element.isInstanceMember()) return instanceFieldAccessorName(element); | |
|
ngeoffray
2013/11/11 10:31:32
Ditto.
sra1
2013/11/14 00:26:31
Done.
| |
| 450 return getNameOfField(element); | |
| 451 } | |
| 452 | |
| 453 String instanceFieldAccessorName(Element element) { | |
| 444 String proposedName = privateName(element.getLibrary(), element.name); | 454 String proposedName = privateName(element.getLibrary(), element.name); |
| 445 return getMappedInstanceName(proposedName); | 455 return getMappedInstanceName(proposedName); |
| 446 } | 456 } |
| 447 | 457 |
| 448 // Construct a new name for the element based on the library and class it is | 458 String instanceFieldPropertyName(Element element) { |
| 449 // in. The name here is not important, we just need to make sure it is | 459 if (element.hasFixedBackendName()) { |
| 450 // unique. If we are minifying, we actually construct the name from the | 460 return element.fixedBackendName(); |
| 451 // minified versions of the class and instance names, but the result is | 461 } |
| 452 // minified once again, so that is not visible in the end result. | 462 // If a class is used anywhere as a mixin, we must make the name unique so |
| 453 String shadowedFieldName(Element fieldElement) { | 463 // that it does not accidentally shadow. Also, the mixin name must be |
| 454 // Check for following situation: Native field ${fieldElement.name} has | 464 // constant over all mixins. |
| 455 // fixed JSName ${fieldElement.nativeName()}, but a subclass shadows this | 465 if (!compiler.world.isUsedAsMixin(element.getEnclosingClass())) { |
| 456 // name. We normally handle that by renaming the superclass field, but we | 466 if (notShadowingAnotherField(element)) { |
|
ngeoffray
2013/11/11 10:31:32
Remove an if and use '&&' ?
sra1
2013/11/14 00:26:31
I prefer not to write !a && b when a is complex,
| |
| 457 // can't do that because native fields have fixed JavaScript names. | 467 String proposedName = privateName(element.getLibrary(), element.name); |
| 458 // In practice this can't happen because we can't inherit from native | 468 return getMappedInstanceName(proposedName); |
| 459 // classes. | 469 } |
| 460 assert (!fieldElement.hasFixedBackendName()); | 470 } |
| 461 | 471 |
| 462 String libraryName = getNameOfLibrary(fieldElement.getLibrary()); | 472 // Construct a new name for the element based on the library and class it is |
| 463 String className = getNameOfClass(fieldElement.getEnclosingClass()); | 473 // in. The name here is not important, we just need to make sure it is |
| 464 String instanceName = instanceFieldName(fieldElement); | 474 // unique. If we are minifying, we actually construct the name from the |
| 475 // minified version of the class name, but the result is minified once | |
| 476 // again, so that is not visible in the end result. | |
| 477 String libraryName = getNameOfLibrary(element.getLibrary()); | |
| 478 String className = getNameOfClass(element.getEnclosingClass()); | |
| 479 String instanceName = privateName(element.getLibrary(), element.name); | |
| 465 return getMappedInstanceName('$libraryName\$$className\$$instanceName'); | 480 return getMappedInstanceName('$libraryName\$$className\$$instanceName'); |
| 466 } | 481 } |
| 467 | 482 |
| 483 bool notShadowingAnotherField(Element element) { | |
| 484 // TODO(sra): Search entire chain to ensure not shadowing anther *field*. | |
|
ngeoffray
2013/11/11 10:31:32
anter -> another
sra1
2013/11/14 00:26:31
Done.
| |
| 485 // This version it tricked into using an ugly name by shadowing of an | |
| 486 // abstract getter. | |
|
ngeoffray
2013/11/11 10:31:32
What would it require to fix this?
sra1
2013/11/14 00:26:31
Done.
| |
| 487 return element.getEnclosingClass().lookupSuperMember(element.name) == null; | |
| 488 } | |
| 489 | |
| 468 String setterName(Element element) { | 490 String setterName(Element element) { |
| 469 // We dynamically create setters from the field-name. The setter name must | 491 // We dynamically create setters from the field-name. The setter name must |
| 470 // therefore be derived from the instance field-name. | 492 // therefore be derived from the instance field-name. |
| 471 LibraryElement library = element.getLibrary(); | 493 LibraryElement library = element.getLibrary(); |
| 472 String name = getMappedInstanceName(privateName(library, element.name)); | 494 String name = getMappedInstanceName(privateName(library, element.name)); |
| 473 return '$setterPrefix$name'; | 495 return '$setterPrefix$name'; |
| 474 } | 496 } |
| 475 | 497 |
| 476 String setterNameFromAccessorName(String name) { | 498 String setterNameFromAccessorName(String name) { |
| 477 // We dynamically create setters from the field-name. The setter name must | 499 // We dynamically create setters from the field-name. The setter name must |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 711 String getNameX(Element element) { | 733 String getNameX(Element element) { |
| 712 if (element.isInstanceMember()) { | 734 if (element.isInstanceMember()) { |
| 713 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY | 735 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY |
| 714 || element.kind == ElementKind.FUNCTION) { | 736 || element.kind == ElementKind.FUNCTION) { |
| 715 return instanceMethodName(element); | 737 return instanceMethodName(element); |
| 716 } else if (element.kind == ElementKind.GETTER) { | 738 } else if (element.kind == ElementKind.GETTER) { |
| 717 return getterName(element); | 739 return getterName(element); |
| 718 } else if (element.kind == ElementKind.SETTER) { | 740 } else if (element.kind == ElementKind.SETTER) { |
| 719 return setterName(element); | 741 return setterName(element); |
| 720 } else if (element.kind == ElementKind.FIELD) { | 742 } else if (element.kind == ElementKind.FIELD) { |
| 721 return instanceFieldName(element); | 743 // TODO(sra): Audit all paths here - do they mean the getter or the |
| 744 // property? | |
|
ngeoffray
2013/11/11 10:31:32
Remove TODO? I guess otherwise it does not pass an
sra1
2013/11/14 00:26:31
Done.
| |
| 745 compiler.internalError('getName for bad kind: ${element.kind}', | |
| 746 node: element.parseNode(compiler)); | |
| 747 return instanceFieldAccessorName(element); | |
| 722 } else { | 748 } else { |
| 723 compiler.internalError('getName for bad kind: ${element.kind}', | 749 compiler.internalError('getName for bad kind: ${element.kind}', |
| 724 node: element.parseNode(compiler)); | 750 node: element.parseNode(compiler)); |
| 725 } | 751 } |
| 726 } else { | 752 } else { |
| 727 // Use declaration element to ensure invariant on [globals]. | 753 // Use declaration element to ensure invariant on [globals]. |
| 728 element = element.declaration; | 754 element = element.declaration; |
| 729 // Dealing with a top-level or static element. | 755 // Dealing with a top-level or static element. |
| 730 String cached = globals[element]; | 756 String cached = globals[element]; |
| 731 if (cached != null) return cached; | 757 if (cached != null) return cached; |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1338 if (!first) { | 1364 if (!first) { |
| 1339 sb.write('_'); | 1365 sb.write('_'); |
| 1340 } | 1366 } |
| 1341 sb.write('_'); | 1367 sb.write('_'); |
| 1342 visit(link.head); | 1368 visit(link.head); |
| 1343 first = true; | 1369 first = true; |
| 1344 } | 1370 } |
| 1345 } | 1371 } |
| 1346 } | 1372 } |
| 1347 } | 1373 } |
| OLD | NEW |