| 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 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 name = "${enclosingClass.name.slowToString()}_" | 306 name = "${enclosingClass.name.slowToString()}_" |
| 307 "${element.name.slowToString()}"; | 307 "${element.name.slowToString()}"; |
| 308 } else { | 308 } else { |
| 309 name = element.name.slowToString(); | 309 name = element.name.slowToString(); |
| 310 } | 310 } |
| 311 } else if (element.isLibrary()) { | 311 } else if (element.isLibrary()) { |
| 312 name = LIBRARY_PREFIX; | 312 name = LIBRARY_PREFIX; |
| 313 } else { | 313 } else { |
| 314 name = element.name.slowToString(); | 314 name = element.name.slowToString(); |
| 315 } | 315 } |
| 316 // Prefix the name with '$' if it is reserved. | |
| 317 return name; | 316 return name; |
| 318 } | 317 } |
| 319 | 318 |
| 320 String getBailoutName(Element element) { | 319 String getBailoutName(Element element) { |
| 321 String name = bailoutNames[element]; | 320 String name = bailoutNames[element]; |
| 322 if (name != null) return name; | 321 if (name != null) return name; |
| 323 bool global = !element.isInstanceMember(); | 322 bool global = !element.isInstanceMember(); |
| 324 String unminifiedName = '${getName(element)}\$bailout'; | 323 String unminifiedName = '${getName(element)}\$bailout'; |
| 325 if (global) { | 324 if (global) { |
| 326 name = getMappedGlobalName(unminifiedName); | 325 name = getMappedGlobalName(unminifiedName); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 356 return setterName(element.getLibrary(), element.name); | 355 return setterName(element.getLibrary(), element.name); |
| 357 } else if (element.kind == ElementKind.FIELD) { | 356 } else if (element.kind == ElementKind.FIELD) { |
| 358 return instanceFieldName(element.getLibrary(), element.name); | 357 return instanceFieldName(element.getLibrary(), element.name); |
| 359 } else { | 358 } else { |
| 360 compiler.internalError('getName for bad kind: ${element.kind}', | 359 compiler.internalError('getName for bad kind: ${element.kind}', |
| 361 node: element.parseNode(compiler)); | 360 node: element.parseNode(compiler)); |
| 362 } | 361 } |
| 363 } else { | 362 } else { |
| 364 // Use declaration element to ensure invariant on [globals]. | 363 // Use declaration element to ensure invariant on [globals]. |
| 365 element = element.declaration; | 364 element = element.declaration; |
| 366 | |
| 367 // Dealing with a top-level or static element. | 365 // Dealing with a top-level or static element. |
| 368 String cached = globals[element]; | 366 String cached = globals[element]; |
| 369 if (cached != null) return cached; | 367 if (cached != null) return cached; |
| 370 | 368 |
| 371 String guess = _computeGuess(element); | 369 String guess = _computeGuess(element); |
| 372 ElementKind kind = element.kind; | 370 ElementKind kind = element.kind; |
| 373 if (identical(kind, ElementKind.VARIABLE) || | 371 if (identical(kind, ElementKind.VARIABLE) || |
| 374 identical(kind, ElementKind.PARAMETER)) { | 372 identical(kind, ElementKind.PARAMETER)) { |
| 375 // The name is not guaranteed to be unique. | 373 // The name is not guaranteed to be unique. |
| 376 return safeName(guess); | 374 return safeName(guess); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 430 } |
| 433 | 431 |
| 434 String safeName(String name) { | 432 String safeName(String name) { |
| 435 if (jsReserved.contains(name) || name.startsWith('\$')) { | 433 if (jsReserved.contains(name) || name.startsWith('\$')) { |
| 436 name = "\$$name"; | 434 name = "\$$name"; |
| 437 assert(!jsReserved.contains(name)); | 435 assert(!jsReserved.contains(name)); |
| 438 } | 436 } |
| 439 return name; | 437 return name; |
| 440 } | 438 } |
| 441 } | 439 } |
| OLD | NEW |