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

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

Issue 11416007: Fix this longstanding bug that luckily did not bite us yet: Use Class.prototype.foo$bailout.call(th… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 { 10 class Namer {
(...skipping 12 matching lines...) Expand all
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 Map<Element, String> globals; 29 final Map<Element, String> globals;
30 final Map<String, int> usedGlobals; 30 final Map<String, int> usedGlobals;
31 final Map<String, LibraryElement> shortPrivateNameOwners; 31 final Map<String, LibraryElement> shortPrivateNameOwners;
32 32
33 /// A cache of names used for bailout methods. We make sure two
karlklose 2012/11/16 09:31:17 I think you should /**...*/ here.
ngeoffray 2012/11/16 10:37:56 Done.
34 /// bailout methods cannot have the same name because if one is
karlklose 2012/11/16 09:31:17 I find "because if one is defined in a class that
ngeoffray 2012/11/16 10:37:56 Done.
35 /// defined in a class that is a subclass of the other, we would
36 /// resolve to the wrong bailout method at runtime. To make it
37 /// simple, we don't keep track of inheritance and always avoid
38 /// similar names.
39 final Set<String> usedBailoutNames;
40 final Map<Element, String> bailoutNames;
41
33 final Map<Constant, String> constantNames; 42 final Map<Constant, String> constantNames;
34 43
35 Namer(this.compiler) 44 Namer(this.compiler)
36 : globals = new Map<Element, String>(), 45 : globals = new Map<Element, String>(),
37 usedGlobals = new Map<String, int>(), 46 usedGlobals = new Map<String, int>(),
38 shortPrivateNameOwners = new Map<String, LibraryElement>(), 47 shortPrivateNameOwners = new Map<String, LibraryElement>(),
48 bailoutNames = new Map<Element, String>(),
49 usedBailoutNames = new Set<String>(),
39 constantNames = new Map<Constant, String>(); 50 constantNames = new Map<Constant, String>();
40 51
41 final String CURRENT_ISOLATE = r'$'; 52 final String CURRENT_ISOLATE = r'$';
42 final String ISOLATE = 'Isolate'; 53 final String ISOLATE = 'Isolate';
43 final String ISOLATE_PROPERTIES = r"$isolateProperties"; 54 final String ISOLATE_PROPERTIES = r"$isolateProperties";
44 /** Some closures must contain their name. The name is stored in 55 /** Some closures must contain their name. The name is stored in
45 * [STATIC_CLOSURE_NAME_NAME]. */ 56 * [STATIC_CLOSURE_NAME_NAME]. */
karlklose 2012/11/16 09:31:17 Not your change, but break before "*/".
ngeoffray 2012/11/16 10:37:56 Done.
46 final String STATIC_CLOSURE_NAME_NAME = r'$name'; 57 final String STATIC_CLOSURE_NAME_NAME = r'$name';
47 static const SourceString CLOSURE_INVOCATION_NAME = 58 static const SourceString CLOSURE_INVOCATION_NAME =
48 Compiler.CALL_OPERATOR_NAME; 59 Compiler.CALL_OPERATOR_NAME;
49 60
50 String constantName(Constant constant) { 61 String constantName(Constant constant) {
51 // In the current implementation it doesn't make sense to give names to 62 // In the current implementation it doesn't make sense to give names to
52 // function constants since the function-implementation itself serves as 63 // function constants since the function-implementation itself serves as
53 // constant and can be accessed directly. 64 // constant and can be accessed directly.
54 assert(!constant.isFunction()); 65 assert(!constant.isFunction());
55 String result = constantNames[constant]; 66 String result = constantNames[constant];
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } else if (identical(element.kind, ElementKind.LIBRARY)) { 241 } else if (identical(element.kind, ElementKind.LIBRARY)) {
231 name = LIBRARY_PREFIX; 242 name = LIBRARY_PREFIX;
232 } else { 243 } else {
233 name = element.name.slowToString(); 244 name = element.name.slowToString();
234 } 245 }
235 // Prefix the name with '$' if it is reserved. 246 // Prefix the name with '$' if it is reserved.
236 return safeName(name); 247 return safeName(name);
237 } 248 }
238 249
239 String getBailoutName(Element element) { 250 String getBailoutName(Element element) {
240 return '${getName(element)}\$bailout'; 251 String name = bailoutNames[element];
252 if (name != null) return name;
253 String candidate = '${getName(element)}\$bailout';
254 name = candidate;
255 int i = 0;
256 while (usedBailoutNames.contains(name)) name = '$candidate${i++}';
karlklose 2012/11/16 09:31:17 Should we have a UniqueElementNameGenerator abstra
257 bailoutNames[element] = name;
258 usedBailoutNames.add(name);
259 return name;
241 } 260 }
242 261
243 /** 262 /**
244 * Returns a preferred JS-id for the given element. The returned id is 263 * Returns a preferred JS-id for the given element. The returned id is
245 * guaranteed to be a valid JS-id. Globals and static fields are furthermore 264 * guaranteed to be a valid JS-id. Globals and static fields are furthermore
246 * guaranteed to be unique. 265 * guaranteed to be unique.
247 * 266 *
248 * For accessing statics consider calling 267 * For accessing statics consider calling
249 * [isolateAccess]/[isolateBailoutAccess] or [isolatePropertyAccess] instead. 268 * [isolateAccess]/[isolateBailoutAccess] or [isolatePropertyAccess] instead.
250 */ 269 */
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 345 }
327 346
328 String safeName(String name) { 347 String safeName(String name) {
329 if (jsReserved.contains(name) || name.startsWith('\$')) { 348 if (jsReserved.contains(name) || name.startsWith('\$')) {
330 name = "\$$name"; 349 name = "\$$name";
331 assert(!jsReserved.contains(name)); 350 assert(!jsReserved.contains(name));
332 } 351 }
333 return name; 352 return name;
334 } 353 }
335 } 354 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698