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

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 10 matching lines...) Expand all
21 final String CURRENT_ISOLATE = r'$'; 21 final String CURRENT_ISOLATE = r'$';
22 22
23 /** 23 /**
24 * Map from top-level or static elements to their unique identifiers provided 24 * Map from top-level or static elements to their unique identifiers provided
25 * by [getName]. 25 * by [getName].
26 * 26 *
27 * Invariant: Keys must be declaration elements. 27 * Invariant: Keys must be declaration elements.
28 */ 28 */
29 final Compiler compiler; 29 final Compiler compiler;
30 final Map<Element, String> globals; 30 final Map<Element, String> globals;
31 final Map<Selector, String> oneShotInterceptorNames;
31 final Map<String, LibraryElement> shortPrivateNameOwners; 32 final Map<String, LibraryElement> shortPrivateNameOwners;
32 final Set<String> usedGlobalNames; 33 final Set<String> usedGlobalNames;
33 final Set<String> usedInstanceNames; 34 final Set<String> usedInstanceNames;
34 final Map<String, String> globalNameMap; 35 final Map<String, String> globalNameMap;
35 final Map<String, String> instanceNameMap; 36 final Map<String, String> instanceNameMap;
36 final Map<String, int> popularNameCounters; 37 final Map<String, int> popularNameCounters;
37 38
38 /** 39 /**
39 * A cache of names used for bailout methods. We make sure two 40 * A cache of names used for bailout methods. We make sure two
40 * bailout methods cannot have the same name because if the two 41 * bailout methods cannot have the same name because if the two
41 * bailout methods are in a class and a subclass, we would 42 * bailout methods are in a class and a subclass, we would
42 * call the wrong bailout method at runtime. To make it 43 * call the wrong bailout method at runtime. To make it
43 * simple, we don't keep track of inheritance and always avoid 44 * simple, we don't keep track of inheritance and always avoid
44 * similar names. 45 * similar names.
45 */ 46 */
46 final Set<String> usedBailoutInstanceNames; 47 final Set<String> usedBailoutInstanceNames;
47 final Map<Element, String> bailoutNames; 48 final Map<Element, String> bailoutNames;
48 49
49 final Map<Constant, String> constantNames; 50 final Map<Constant, String> constantNames;
50 51
51 Namer(this.compiler) 52 Namer(this.compiler)
52 : globals = new Map<Element, String>(), 53 : globals = new Map<Element, String>(),
54 oneShotInterceptorNames = new Map<Selector, String>(),
53 shortPrivateNameOwners = new Map<String, LibraryElement>(), 55 shortPrivateNameOwners = new Map<String, LibraryElement>(),
54 bailoutNames = new Map<Element, String>(), 56 bailoutNames = new Map<Element, String>(),
55 usedBailoutInstanceNames = new Set<String>(), 57 usedBailoutInstanceNames = new Set<String>(),
56 usedGlobalNames = new Set<String>(), 58 usedGlobalNames = new Set<String>(),
57 usedInstanceNames = new Set<String>(), 59 usedInstanceNames = new Set<String>(),
58 instanceNameMap = new Map<String, String>(), 60 instanceNameMap = new Map<String, String>(),
59 globalNameMap = new Map<String, String>(), 61 globalNameMap = new Map<String, String>(),
60 constantNames = new Map<Constant, String>(), 62 constantNames = new Map<Constant, String>(),
61 popularNameCounters = new Map<String, int>(); 63 popularNameCounters = new Map<String, int>();
62 64
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 name = element.name.slowToString(); 340 name = element.name.slowToString();
339 } 341 }
340 } else if (element.isLibrary()) { 342 } else if (element.isLibrary()) {
341 name = LIBRARY_PREFIX; 343 name = LIBRARY_PREFIX;
342 } else { 344 } else {
343 name = element.name.slowToString(); 345 name = element.name.slowToString();
344 } 346 }
345 return name; 347 return name;
346 } 348 }
347 349
348 String getSpecializedName(Element element, Collection<ClassElement> classes) { 350 String getInterceptorName(Element element, Collection<ClassElement> classes) {
351 if (classes.contains(compiler.objectClass)) {
352 // If the object class is in the set of intercepted classes, we
353 // need to go through the generic getInterceptorMethod.
354 return getName(element);
355 }
349 // This gets the minified name, but it doesn't really make much difference. 356 // This gets the minified name, but it doesn't really make much difference.
350 // The important thing is that it is a unique name. 357 // The important thing is that it is a unique name.
351 StringBuffer buffer = new StringBuffer('${getName(element)}\$'); 358 StringBuffer buffer = new StringBuffer('${getName(element)}\$');
352 for (ClassElement cls in classes) { 359 for (ClassElement cls in classes) {
353 buffer.add(getName(cls)); 360 buffer.add(getName(cls));
354 } 361 }
355 return getMappedGlobalName(buffer.toString()); 362 return getMappedGlobalName(buffer.toString());
356 } 363 }
357 364
358 String getBailoutName(Element element) { 365 String getBailoutName(Element element) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 return 'is\$${getName(element)}'; 476 return 'is\$${getName(element)}';
470 } 477 }
471 478
472 String safeName(String name) { 479 String safeName(String name) {
473 if (jsReserved.contains(name) || name.startsWith('\$')) { 480 if (jsReserved.contains(name) || name.startsWith('\$')) {
474 name = "\$$name"; 481 name = "\$$name";
475 assert(!jsReserved.contains(name)); 482 assert(!jsReserved.contains(name));
476 } 483 }
477 return name; 484 return name;
478 } 485 }
486
487 String oneShotInterceptorName(Selector selector) {
488 String cached = oneShotInterceptorNames[selector];
489 if (cached != null) return cached;
490 SourceString name = Elements.operatorNameToIdentifier(selector.name);
sra1 2013/01/23 21:21:30 Can typed selectors get here? There may be many ty
ngeoffray 2013/01/24 08:39:15 I believe typed selector can come here, but I'd pr
491 String result = getFreshName(name.slowToString(), usedGlobalNames);
492 oneShotInterceptorNames[selector] = result;
493 return result;
494 }
479 } 495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698