Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/namer.dart

Issue 12033056: Implement "one-shot" interceptors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 29 matching lines...) Expand all
40 final String CURRENT_ISOLATE = r'$'; 40 final String CURRENT_ISOLATE = r'$';
41 41
42 /** 42 /**
43 * Map from top-level or static elements to their unique identifiers provided 43 * Map from top-level or static elements to their unique identifiers provided
44 * by [getName]. 44 * by [getName].
45 * 45 *
46 * Invariant: Keys must be declaration elements. 46 * Invariant: Keys must be declaration elements.
47 */ 47 */
48 final Compiler compiler; 48 final Compiler compiler;
49 final Map<Element, String> globals; 49 final Map<Element, String> globals;
50 final Map<Selector, String> oneShotInterceptorNames;
50 final Map<String, LibraryElement> shortPrivateNameOwners; 51 final Map<String, LibraryElement> shortPrivateNameOwners;
51 final Set<String> usedGlobalNames; 52 final Set<String> usedGlobalNames;
52 final Set<String> usedInstanceNames; 53 final Set<String> usedInstanceNames;
53 final Map<String, String> globalNameMap; 54 final Map<String, String> globalNameMap;
54 final Map<String, String> instanceNameMap; 55 final Map<String, String> instanceNameMap;
55 final Map<String, String> operatorNameMap; 56 final Map<String, String> operatorNameMap;
56 final Map<String, int> popularNameCounters; 57 final Map<String, int> popularNameCounters;
57 58
58 /** 59 /**
59 * A cache of names used for bailout methods. We make sure two 60 * A cache of names used for bailout methods. We make sure two
60 * bailout methods cannot have the same name because if the two 61 * bailout methods cannot have the same name because if the two
61 * bailout methods are in a class and a subclass, we would 62 * bailout methods are in a class and a subclass, we would
62 * call the wrong bailout method at runtime. To make it 63 * call the wrong bailout method at runtime. To make it
63 * simple, we don't keep track of inheritance and always avoid 64 * simple, we don't keep track of inheritance and always avoid
64 * similar names. 65 * similar names.
65 */ 66 */
66 final Set<String> usedBailoutInstanceNames; 67 final Set<String> usedBailoutInstanceNames;
67 final Map<Element, String> bailoutNames; 68 final Map<Element, String> bailoutNames;
68 69
69 final Map<Constant, String> constantNames; 70 final Map<Constant, String> constantNames;
70 71
71 Namer(this.compiler) 72 Namer(this.compiler)
72 : globals = new Map<Element, String>(), 73 : globals = new Map<Element, String>(),
74 oneShotInterceptorNames = new Map<Selector, String>(),
73 shortPrivateNameOwners = new Map<String, LibraryElement>(), 75 shortPrivateNameOwners = new Map<String, LibraryElement>(),
74 bailoutNames = new Map<Element, String>(), 76 bailoutNames = new Map<Element, String>(),
75 usedBailoutInstanceNames = new Set<String>(), 77 usedBailoutInstanceNames = new Set<String>(),
76 usedGlobalNames = new Set<String>(), 78 usedGlobalNames = new Set<String>(),
77 usedInstanceNames = new Set<String>(), 79 usedInstanceNames = new Set<String>(),
78 instanceNameMap = new Map<String, String>(), 80 instanceNameMap = new Map<String, String>(),
79 operatorNameMap = new Map<String, String>(), 81 operatorNameMap = new Map<String, String>(),
80 globalNameMap = new Map<String, String>(), 82 globalNameMap = new Map<String, String>(),
81 constantNames = new Map<Constant, String>(), 83 constantNames = new Map<Constant, String>(),
82 popularNameCounters = new Map<String, int>(); 84 popularNameCounters = new Map<String, int>();
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 name = element.name.slowToString(); 389 name = element.name.slowToString();
388 } 390 }
389 } else if (element.isLibrary()) { 391 } else if (element.isLibrary()) {
390 name = LIBRARY_PREFIX; 392 name = LIBRARY_PREFIX;
391 } else { 393 } else {
392 name = element.name.slowToString(); 394 name = element.name.slowToString();
393 } 395 }
394 return name; 396 return name;
395 } 397 }
396 398
397 String getSpecializedName(Element element, Collection<ClassElement> classes) { 399 String getInterceptorName(Element element, Collection<ClassElement> classes) {
400 if (classes.contains(compiler.objectClass)) {
401 // If the object class is in the set of intercepted classes, we
402 // need to go through the generic getInterceptorMethod.
403 return getName(element);
404 }
398 // This gets the minified name, but it doesn't really make much difference. 405 // This gets the minified name, but it doesn't really make much difference.
399 // The important thing is that it is a unique name. 406 // The important thing is that it is a unique name.
400 StringBuffer buffer = new StringBuffer('${getName(element)}\$'); 407 StringBuffer buffer = new StringBuffer('${getName(element)}\$');
401 for (ClassElement cls in classes) { 408 for (ClassElement cls in classes) {
402 buffer.add(getName(cls)); 409 buffer.add(getName(cls));
403 } 410 }
404 return getMappedGlobalName(buffer.toString()); 411 return getMappedGlobalName(buffer.toString());
405 } 412 }
406 413
407 String getBailoutName(Element element) { 414 String getBailoutName(Element element) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 * and also ensures it won't clash with other identifiers. 533 * and also ensures it won't clash with other identifiers.
527 */ 534 */
528 String safeName(String name) { 535 String safeName(String name) {
529 if (jsReserved.contains(name) || name.startsWith(r'$')) { 536 if (jsReserved.contains(name) || name.startsWith(r'$')) {
530 name = '\$$name'; 537 name = '\$$name';
531 } 538 }
532 assert(!jsReserved.contains(name)); 539 assert(!jsReserved.contains(name));
533 return name; 540 return name;
534 } 541 }
535 542
543 String oneShotInterceptorName(Selector selector) {
544 // TODO(ngeoffray): What to do about typed selectors? We could
545 // filter them out, or keep them and hope the generated one shot
546 // interceptor takes advantage of the type.
547 String cached = oneShotInterceptorNames[selector];
548 if (cached != null) return cached;
549 SourceString name = operatorNameToIdentifier(selector.name);
550 String result = getFreshName(name.slowToString(), usedGlobalNames);
551 oneShotInterceptorNames[selector] = result;
552 return result;
553 }
554
536 SourceString operatorNameToIdentifier(SourceString name) { 555 SourceString operatorNameToIdentifier(SourceString name) {
537 if (name == null) return null; 556 if (name == null) return null;
538 String value = name.stringValue; 557 String value = name.stringValue;
539 if (value == null) { 558 if (value == null) {
540 return name; 559 return name;
541 } else if (value == '==') { 560 } else if (value == '==') {
542 return const SourceString(r'$eq'); 561 return const SourceString(r'$eq');
543 } else if (value == '~') { 562 } else if (value == '~') {
544 return const SourceString(r'$not'); 563 return const SourceString(r'$not');
545 } else if (value == '[]') { 564 } else if (value == '[]') {
(...skipping 30 matching lines...) Expand all
576 return const SourceString(r'$or'); 595 return const SourceString(r'$or');
577 } else if (value == '-') { 596 } else if (value == '-') {
578 return const SourceString(r'$sub'); 597 return const SourceString(r'$sub');
579 } else if (value == 'unary-') { 598 } else if (value == 'unary-') {
580 return const SourceString(r'$negate'); 599 return const SourceString(r'$negate');
581 } else { 600 } else {
582 return name; 601 return name;
583 } 602 }
584 } 603 }
585 } 604 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698