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

Side by Side Diff: lib/compiler/implementation/namer.dart

Issue 10855174: Lazy implementation of final variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase wrt CL 10832351. Created 8 years, 4 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 /** 5 /**
6 * Assigns JavaScript identifiers to Dart variables, class-names and members. 6 * Assigns JavaScript identifiers to Dart variables, class-names and members.
7 */ 7 */
8 class Namer { 8 class Namer {
9 final Compiler compiler; 9 final Compiler compiler;
10 10
(...skipping 17 matching lines...) Expand all
28 usedGlobals = new Map<String, int>(), 28 usedGlobals = new Map<String, int>(),
29 usedPrivateNames = new Map<String, Set<LibraryElement>>(), 29 usedPrivateNames = new Map<String, Set<LibraryElement>>(),
30 shortPrivateNameOwners = new Map<String, LibraryElement>(); 30 shortPrivateNameOwners = new Map<String, LibraryElement>();
31 31
32 final String CURRENT_ISOLATE = @'$'; 32 final String CURRENT_ISOLATE = @'$';
33 final String ISOLATE = 'Isolate'; 33 final String ISOLATE = 'Isolate';
34 final String ISOLATE_PROPERTIES = @"$isolateProperties"; 34 final String ISOLATE_PROPERTIES = @"$isolateProperties";
35 /** Some closures must contain their name. The name is stored in 35 /** Some closures must contain their name. The name is stored in
36 * [STATIC_CLOSURE_NAME_NAME]. */ 36 * [STATIC_CLOSURE_NAME_NAME]. */
37 final String STATIC_CLOSURE_NAME_NAME = @'$name'; 37 final String STATIC_CLOSURE_NAME_NAME = @'$name';
38 // TODO(floitsch): make sure the sentinel can't clash with other fields.
39 final String LAZY_INITIALIZATION_SENTINEL = @"$lazySentinel";
38 static final SourceString CLOSURE_INVOCATION_NAME = 40 static final SourceString CLOSURE_INVOCATION_NAME =
39 Compiler.CALL_OPERATOR_NAME; 41 Compiler.CALL_OPERATOR_NAME;
40 42
41 43
42 String closureInvocationName(Selector selector) { 44 String closureInvocationName(Selector selector) {
43 // TODO(floitsch): mangle, while not conflicting with instance names. 45 // TODO(floitsch): mangle, while not conflicting with instance names.
44 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, 46 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME,
45 selector); 47 selector);
46 } 48 }
47 49
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 kind === ElementKind.LIBRARY) { 276 kind === ElementKind.LIBRARY) {
275 String result = getFreshGlobalName(guess); 277 String result = getFreshGlobalName(guess);
276 globals[element] = result; 278 globals[element] = result;
277 return result; 279 return result;
278 } 280 }
279 compiler.internalError('getName for unknown kind: ${element.kind}', 281 compiler.internalError('getName for unknown kind: ${element.kind}',
280 node: element.parseNode(compiler)); 282 node: element.parseNode(compiler));
281 } 283 }
282 } 284 }
283 285
286 String getLazyInitializerName(Element element) {
287 // TODO(floitsch): mangle while not conflicting with other statics.
288 assert(Elements.isStaticOrTopLevelField(element));
289 return "get\$${getName(element)}";
290 }
291
292 String getLazyInitializerBailoutName(Element element) {
293 return "${getLazyInitializerName}\$bailout";
294 }
295
284 String isolatePropertiesAccess(Element element) { 296 String isolatePropertiesAccess(Element element) {
285 return "$ISOLATE.$ISOLATE_PROPERTIES.${getName(element)}"; 297 return "$ISOLATE.$ISOLATE_PROPERTIES.${getName(element)}";
286 } 298 }
287 299
288 String isolatePropertiesAccessForConstant(String constantName) { 300 String isolatePropertiesAccessForConstant(String constantName) {
289 return "$ISOLATE.$ISOLATE_PROPERTIES.$constantName"; 301 return "$ISOLATE.$ISOLATE_PROPERTIES.$constantName";
290 } 302 }
291 303
292 String isolateAccess(Element element) { 304 String isolateAccess(Element element) {
293 return "$CURRENT_ISOLATE.${getName(element)}"; 305 return "$CURRENT_ISOLATE.${getName(element)}";
294 } 306 }
295 307
296 String isolateBailoutAccess(Element element) { 308 String isolateBailoutAccess(Element element) {
297 return '${isolateAccess(element)}\$bailout'; 309 return '${isolateAccess(element)}\$bailout';
298 } 310 }
299 311
312 String isolateLazyInitializerAccess(Element element) {
313 return "$CURRENT_ISOLATE.${getLazyInitializerName(element)}";
314 }
315
316 String isolateLazyInitializerBailoutAccess(Element element) {
317 return "$CURRENT_ISOLATE.${getLazyInitializerName(element)}\$bailout";
318 }
319
300 String operatorIs(Element element) { 320 String operatorIs(Element element) {
301 return 'is\$${getName(element)}'; 321 return 'is\$${getName(element)}';
302 } 322 }
303 323
304 String safeName(String name) { 324 String safeName(String name) {
305 if (jsReserved.contains(name) || name.startsWith('\$')) { 325 if (jsReserved.contains(name) || name.startsWith('\$')) {
306 name = "\$$name"; 326 name = "\$$name";
307 assert(!jsReserved.contains(name)); 327 assert(!jsReserved.contains(name));
308 } 328 }
309 return name; 329 return name;
310 } 330 }
311 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698