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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 name = element.name.slowToString(); | 529 name = element.name.slowToString(); |
530 } | 530 } |
531 } else if (element.isLibrary()) { | 531 } else if (element.isLibrary()) { |
532 name = LIBRARY_PREFIX; | 532 name = LIBRARY_PREFIX; |
533 } else { | 533 } else { |
534 name = element.name.slowToString(); | 534 name = element.name.slowToString(); |
535 } | 535 } |
536 return name; | 536 return name; |
537 } | 537 } |
538 | 538 |
539 String getInterceptorSuffix(Collection<ClassElement> classes) { | 539 String getInterceptorSuffix(Iterable<ClassElement> classes) { |
540 String abbreviate(ClassElement cls) { | 540 String abbreviate(ClassElement cls) { |
541 if (cls == compiler.objectClass) return "o"; | 541 if (cls == compiler.objectClass) return "o"; |
542 JavaScriptBackend backend = compiler.backend; | 542 JavaScriptBackend backend = compiler.backend; |
543 if (cls == backend.jsStringClass) return "s"; | 543 if (cls == backend.jsStringClass) return "s"; |
544 if (cls == backend.jsArrayClass) return "a"; | 544 if (cls == backend.jsArrayClass) return "a"; |
545 if (cls == backend.jsDoubleClass) return "d"; | 545 if (cls == backend.jsDoubleClass) return "d"; |
546 if (cls == backend.jsIntClass) return "i"; | 546 if (cls == backend.jsIntClass) return "i"; |
547 if (cls == backend.jsNumberClass) return "n"; | 547 if (cls == backend.jsNumberClass) return "n"; |
548 if (cls == backend.jsNullClass) return "u"; | 548 if (cls == backend.jsNullClass) return "u"; |
549 if (cls == backend.jsFunctionClass) return "f"; | 549 if (cls == backend.jsFunctionClass) return "f"; |
550 if (cls == backend.jsBoolClass) return "b"; | 550 if (cls == backend.jsBoolClass) return "b"; |
551 if (cls == backend.jsInterceptorClass) return "I"; | 551 if (cls == backend.jsInterceptorClass) return "I"; |
552 return cls.name.slowToString(); | 552 return cls.name.slowToString(); |
553 } | 553 } |
554 List<String> names = classes | 554 List<String> names = classes |
555 .where((cls) => !cls.isNative()) | 555 .where((cls) => !cls.isNative()) |
556 .map(abbreviate) | 556 .map(abbreviate) |
557 .toList(); | 557 .toList(); |
558 // There is one dispatch mechanism for all native classes. | 558 // There is one dispatch mechanism for all native classes. |
559 if (classes.any((cls) => cls.isNative())) { | 559 if (classes.any((cls) => cls.isNative())) { |
560 names.add("x"); | 560 names.add("x"); |
561 } | 561 } |
562 // Sort the names of the classes after abbreviating them to ensure | 562 // Sort the names of the classes after abbreviating them to ensure |
563 // the suffix is stable and predictable for the suggested names. | 563 // the suffix is stable and predictable for the suggested names. |
564 names.sort(); | 564 names.sort(); |
565 return names.join(); | 565 return names.join(); |
566 } | 566 } |
567 | 567 |
568 String getInterceptorName(Element element, Collection<ClassElement> classes) { | 568 String getInterceptorName(Element element, Iterable<ClassElement> classes) { |
569 JavaScriptBackend backend = compiler.backend; | 569 JavaScriptBackend backend = compiler.backend; |
570 if (classes.contains(backend.jsInterceptorClass)) { | 570 if (classes.contains(backend.jsInterceptorClass)) { |
571 // If the base Interceptor class is in the set of intercepted classes, we | 571 // If the base Interceptor class is in the set of intercepted classes, we |
572 // need to go through the generic getInterceptorMethod, since any subclass | 572 // need to go through the generic getInterceptorMethod, since any subclass |
573 // of the base Interceptor could match. | 573 // of the base Interceptor could match. |
574 return getName(element); | 574 return getName(element); |
575 } | 575 } |
576 String suffix = getInterceptorSuffix(classes); | 576 String suffix = getInterceptorSuffix(classes); |
577 return getMappedGlobalName("${element.name.slowToString()}\$$suffix"); | 577 return getMappedGlobalName("${element.name.slowToString()}\$$suffix"); |
578 } | 578 } |
579 | 579 |
580 String getOneShotInterceptorName(Selector selector, | 580 String getOneShotInterceptorName(Selector selector, |
581 Collection<ClassElement> classes) { | 581 Iterable<ClassElement> classes) { |
582 JavaScriptBackend backend = compiler.backend; | 582 JavaScriptBackend backend = compiler.backend; |
583 // The one-shot name is a global name derived from the invocation name. To | 583 // The one-shot name is a global name derived from the invocation name. To |
584 // avoid instability we would like the names to be unique and not clash with | 584 // avoid instability we would like the names to be unique and not clash with |
585 // other global names. | 585 // other global names. |
586 | 586 |
587 String root = invocationName(selector); // Is already safe. | 587 String root = invocationName(selector); // Is already safe. |
588 | 588 |
589 if (classes.contains(backend.jsInterceptorClass)) { | 589 if (classes.contains(backend.jsInterceptorClass)) { |
590 // If the base Interceptor class is in the set of intercepted classes, | 590 // If the base Interceptor class is in the set of intercepted classes, |
591 // this is the most general specialization which uses the generic | 591 // this is the most general specialization which uses the generic |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 hash = hash ^ (hash >> 6); | 1125 hash = hash ^ (hash >> 6); |
1126 return hash; | 1126 return hash; |
1127 } | 1127 } |
1128 | 1128 |
1129 static int _finish(int hash) { | 1129 static int _finish(int hash) { |
1130 hash = _MASK & (hash + (((_MASK >> 3) & hash) << 3)); | 1130 hash = _MASK & (hash + (((_MASK >> 3) & hash) << 3)); |
1131 hash = hash & (hash >> 11); | 1131 hash = hash & (hash >> 11); |
1132 return _MASK & (hash + (((_MASK >> 15) & hash) << 15)); | 1132 return _MASK & (hash + (((_MASK >> 15) & hash) << 15)); |
1133 } | 1133 } |
1134 } | 1134 } |
OLD | NEW |