Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 : globals = new Map<Element, String>(), | 26 : globals = new Map<Element, String>(), |
| 27 usedGlobals = new Map<String, int>(), | 27 usedGlobals = new Map<String, int>(), |
| 28 shortPrivateNameOwners = new Map<String, LibraryElement>(); | 28 shortPrivateNameOwners = new Map<String, LibraryElement>(); |
| 29 | 29 |
| 30 final String CURRENT_ISOLATE = @'$'; | 30 final String CURRENT_ISOLATE = @'$'; |
| 31 final String ISOLATE = 'Isolate'; | 31 final String ISOLATE = 'Isolate'; |
| 32 final String ISOLATE_PROPERTIES = @"$isolateProperties"; | 32 final String ISOLATE_PROPERTIES = @"$isolateProperties"; |
| 33 /** Some closures must contain their name. The name is stored in | 33 /** Some closures must contain their name. The name is stored in |
| 34 * [STATIC_CLOSURE_NAME_NAME]. */ | 34 * [STATIC_CLOSURE_NAME_NAME]. */ |
| 35 final String STATIC_CLOSURE_NAME_NAME = @'$name'; | 35 final String STATIC_CLOSURE_NAME_NAME = @'$name'; |
| 36 // TODO(floitsch): make sure the sentinel can't clash with other fields. | |
|
kasperl
2012/09/05 08:25:24
Where is this used?
floitsch
2012/09/05 09:31:07
Removed.
done.
| |
| 37 final String LAZY_INITIALIZATION_SENTINEL = @"$lazySentinel"; | |
| 36 static const SourceString CLOSURE_INVOCATION_NAME = | 38 static const SourceString CLOSURE_INVOCATION_NAME = |
| 37 Compiler.CALL_OPERATOR_NAME; | 39 Compiler.CALL_OPERATOR_NAME; |
| 38 | 40 |
| 39 | 41 |
| 40 String closureInvocationName(Selector selector) { | 42 String closureInvocationName(Selector selector) { |
| 41 // TODO(floitsch): mangle, while not conflicting with instance names. | 43 // TODO(floitsch): mangle, while not conflicting with instance names. |
| 42 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, | 44 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, |
| 43 selector); | 45 selector); |
| 44 } | 46 } |
| 45 | 47 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 kind === ElementKind.LIBRARY) { | 268 kind === ElementKind.LIBRARY) { |
| 267 String result = getFreshGlobalName(guess); | 269 String result = getFreshGlobalName(guess); |
| 268 globals[element] = result; | 270 globals[element] = result; |
| 269 return result; | 271 return result; |
| 270 } | 272 } |
| 271 compiler.internalError('getName for unknown kind: ${element.kind}', | 273 compiler.internalError('getName for unknown kind: ${element.kind}', |
| 272 node: element.parseNode(compiler)); | 274 node: element.parseNode(compiler)); |
| 273 } | 275 } |
| 274 } | 276 } |
| 275 | 277 |
| 278 String getLazyInitializerName(Element element) { | |
| 279 // TODO(floitsch): mangle while not conflicting with other statics. | |
| 280 assert(Elements.isStaticOrTopLevelField(element)); | |
| 281 return "get\$${getName(element)}"; | |
| 282 } | |
| 283 | |
| 276 String isolatePropertiesAccess(Element element) { | 284 String isolatePropertiesAccess(Element element) { |
| 277 return "$ISOLATE.$ISOLATE_PROPERTIES.${getName(element)}"; | 285 return "$ISOLATE.$ISOLATE_PROPERTIES.${getName(element)}"; |
| 278 } | 286 } |
| 279 | 287 |
| 280 String isolatePropertiesAccessForConstant(String constantName) { | 288 String isolatePropertiesAccessForConstant(String constantName) { |
| 281 return "$ISOLATE.$ISOLATE_PROPERTIES.$constantName"; | 289 return "$ISOLATE.$ISOLATE_PROPERTIES.$constantName"; |
| 282 } | 290 } |
| 283 | 291 |
| 284 String isolateAccess(Element element) { | 292 String isolateAccess(Element element) { |
| 285 return "$CURRENT_ISOLATE.${getName(element)}"; | 293 return "$CURRENT_ISOLATE.${getName(element)}"; |
| 286 } | 294 } |
| 287 | 295 |
| 288 String isolateBailoutAccess(Element element) { | 296 String isolateBailoutAccess(Element element) { |
| 289 return '${isolateAccess(element)}\$bailout'; | 297 return '${isolateAccess(element)}\$bailout'; |
| 290 } | 298 } |
| 291 | 299 |
| 300 String isolateLazyInitializerAccess(Element element) { | |
| 301 return "$CURRENT_ISOLATE.${getLazyInitializerName(element)}"; | |
| 302 } | |
| 303 | |
| 292 String operatorIs(Element element) { | 304 String operatorIs(Element element) { |
| 293 return 'is\$${getName(element)}'; | 305 return 'is\$${getName(element)}'; |
| 294 } | 306 } |
| 295 | 307 |
| 296 String safeName(String name) { | 308 String safeName(String name) { |
| 297 if (jsReserved.contains(name) || name.startsWith('\$')) { | 309 if (jsReserved.contains(name) || name.startsWith('\$')) { |
| 298 name = "\$$name"; | 310 name = "\$$name"; |
| 299 assert(!jsReserved.contains(name)); | 311 assert(!jsReserved.contains(name)); |
| 300 } | 312 } |
| 301 return name; | 313 return name; |
| 302 } | 314 } |
| 303 } | 315 } |
| OLD | NEW |