| 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 /** | 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 Loading... |
| 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 final SourceString CLOSURE_INVOCATION_NAME = Compiler.CALL_OPERATOR_NAME; | 40 final SourceString CLOSURE_INVOCATION_NAME = Compiler.CALL_OPERATOR_NAME; |
| 39 | 41 |
| 40 | 42 |
| 41 String closureInvocationName(Selector selector) { | 43 String closureInvocationName(Selector selector) { |
| 42 // TODO(floitsch): mangle, while not conflicting with instance names. | 44 // TODO(floitsch): mangle, while not conflicting with instance names. |
| 43 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, | 45 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, |
| 44 selector); | 46 selector); |
| 45 } | 47 } |
| 46 | 48 |
| 47 String breakLabelName(LabelElement label) { | 49 String breakLabelName(LabelElement label) { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 kind === ElementKind.LIBRARY) { | 275 kind === ElementKind.LIBRARY) { |
| 274 String result = getFreshGlobalName(guess); | 276 String result = getFreshGlobalName(guess); |
| 275 globals[element] = result; | 277 globals[element] = result; |
| 276 return result; | 278 return result; |
| 277 } | 279 } |
| 278 compiler.internalError('getName for unknown kind: ${element.kind}', | 280 compiler.internalError('getName for unknown kind: ${element.kind}', |
| 279 node: element.parseNode(compiler)); | 281 node: element.parseNode(compiler)); |
| 280 } | 282 } |
| 281 } | 283 } |
| 282 | 284 |
| 285 String getLazyInitializerName(Element element) { |
| 286 // TODO(floitsch): mangle while not conflicting with other statics. |
| 287 assert(Elements.isStaticOrTopLevelField(element)); |
| 288 return "get\$${getName(element)}"; |
| 289 } |
| 290 |
| 291 String getLazyInitializerBailoutName(Element element) { |
| 292 return "${getLazyInitializerName}\$bailout"; |
| 293 } |
| 294 |
| 283 String isolatePropertiesAccess(Element element) { | 295 String isolatePropertiesAccess(Element element) { |
| 284 return "$ISOLATE.$ISOLATE_PROPERTIES.${getName(element)}"; | 296 return "$ISOLATE.$ISOLATE_PROPERTIES.${getName(element)}"; |
| 285 } | 297 } |
| 286 | 298 |
| 287 String isolatePropertiesAccessForConstant(String constantName) { | 299 String isolatePropertiesAccessForConstant(String constantName) { |
| 288 return "$ISOLATE.$ISOLATE_PROPERTIES.$constantName"; | 300 return "$ISOLATE.$ISOLATE_PROPERTIES.$constantName"; |
| 289 } | 301 } |
| 290 | 302 |
| 291 String isolateAccess(Element element) { | 303 String isolateAccess(Element element) { |
| 292 return "$CURRENT_ISOLATE.${getName(element)}"; | 304 return "$CURRENT_ISOLATE.${getName(element)}"; |
| 293 } | 305 } |
| 294 | 306 |
| 295 String isolateBailoutAccess(Element element) { | 307 String isolateBailoutAccess(Element element) { |
| 296 return '${isolateAccess(element)}\$bailout'; | 308 return '${isolateAccess(element)}\$bailout'; |
| 297 } | 309 } |
| 298 | 310 |
| 311 String isolateLazyInitializerAccess(Element element) { |
| 312 return "$CURRENT_ISOLATE.${getLazyInitializerName(element)}"; |
| 313 } |
| 314 |
| 315 String isolateLazyInitializerBailoutAccess(Element element) { |
| 316 return "$CURRENT_ISOLATE.${getLazyInitializerName(element)}\$bailout"; |
| 317 } |
| 318 |
| 299 String operatorIs(Element element) { | 319 String operatorIs(Element element) { |
| 300 return 'is\$${getName(element)}'; | 320 return 'is\$${getName(element)}'; |
| 301 } | 321 } |
| 302 | 322 |
| 303 String safeName(String name) { | 323 String safeName(String name) { |
| 304 if (jsReserved.contains(name) || name.startsWith('\$')) { | 324 if (jsReserved.contains(name) || name.startsWith('\$')) { |
| 305 name = "\$$name"; | 325 name = "\$$name"; |
| 306 assert(!jsReserved.contains(name)); | 326 assert(!jsReserved.contains(name)); |
| 307 } | 327 } |
| 308 return name; | 328 return name; |
| 309 } | 329 } |
| 310 } | 330 } |
| OLD | NEW |