| 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 implements ClosureNamer { | 10 class Namer implements ClosureNamer { |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 String newName = getMappedGlobalName('${getName(element)}\$bailout'); | 516 String newName = getMappedGlobalName('${getName(element)}\$bailout'); |
| 517 return '$CURRENT_ISOLATE.$newName'; | 517 return '$CURRENT_ISOLATE.$newName'; |
| 518 } | 518 } |
| 519 | 519 |
| 520 String isolateLazyInitializerAccess(Element element) { | 520 String isolateLazyInitializerAccess(Element element) { |
| 521 return "$CURRENT_ISOLATE.${getLazyInitializerName(element)}"; | 521 return "$CURRENT_ISOLATE.${getLazyInitializerName(element)}"; |
| 522 } | 522 } |
| 523 | 523 |
| 524 String operatorIsPrefix() => r'$is'; | 524 String operatorIsPrefix() => r'$is'; |
| 525 | 525 |
| 526 String operatorAsPrefix() => r'$as'; |
| 527 |
| 526 String operatorIs(Element element) { | 528 String operatorIs(Element element) { |
| 527 // TODO(erikcorry): Reduce from $isx to ix when we are minifying. | 529 // TODO(erikcorry): Reduce from $isx to ix when we are minifying. |
| 528 return '${operatorIsPrefix()}${getName(element)}'; | 530 return '${operatorIsPrefix()}${getName(element)}'; |
| 529 } | 531 } |
| 530 | 532 |
| 531 /* | 533 /* |
| 532 * Returns a name that does not clash with reserved JS keywords, | 534 * Returns a name that does not clash with reserved JS keywords, |
| 533 * and also ensures it won't clash with other identifiers. | 535 * and also ensures it won't clash with other identifiers. |
| 534 */ | 536 */ |
| 535 String safeName(String name) { | 537 String safeName(String name) { |
| 536 if (jsReserved.contains(name) || name.startsWith(r'$')) { | 538 if (jsReserved.contains(name) || name.startsWith(r'$')) { |
| 537 name = '\$$name'; | 539 name = '\$$name'; |
| 538 } | 540 } |
| 539 assert(!jsReserved.contains(name)); | 541 assert(!jsReserved.contains(name)); |
| 540 return name; | 542 return name; |
| 541 } | 543 } |
| 542 | 544 |
| 545 String substitutionName(Element element) { |
| 546 return '${operatorAsPrefix()}${getName(element)}'; |
| 547 } |
| 548 |
| 543 String oneShotInterceptorName(Selector selector) { | 549 String oneShotInterceptorName(Selector selector) { |
| 544 // TODO(ngeoffray): What to do about typed selectors? We could | 550 // TODO(ngeoffray): What to do about typed selectors? We could |
| 545 // filter them out, or keep them and hope the generated one shot | 551 // filter them out, or keep them and hope the generated one shot |
| 546 // interceptor takes advantage of the type. | 552 // interceptor takes advantage of the type. |
| 547 String cached = oneShotInterceptorNames[selector]; | 553 String cached = oneShotInterceptorNames[selector]; |
| 548 if (cached != null) return cached; | 554 if (cached != null) return cached; |
| 549 SourceString name = operatorNameToIdentifier(selector.name); | 555 SourceString name = operatorNameToIdentifier(selector.name); |
| 550 String result = getFreshName(name.slowToString(), usedGlobalNames); | 556 String result = getFreshName(name.slowToString(), usedGlobalNames); |
| 551 oneShotInterceptorNames[selector] = result; | 557 oneShotInterceptorNames[selector] = result; |
| 552 return result; | 558 return result; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 return const SourceString(r'$or'); | 601 return const SourceString(r'$or'); |
| 596 } else if (value == '-') { | 602 } else if (value == '-') { |
| 597 return const SourceString(r'$sub'); | 603 return const SourceString(r'$sub'); |
| 598 } else if (value == 'unary-') { | 604 } else if (value == 'unary-') { |
| 599 return const SourceString(r'$negate'); | 605 return const SourceString(r'$negate'); |
| 600 } else { | 606 } else { |
| 601 return name; | 607 return name; |
| 602 } | 608 } |
| 603 } | 609 } |
| 604 } | 610 } |
| OLD | NEW |