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

Unified Diff: frog/leg/namer.dart

Issue 9415005: Support implicitly bound closures (aka. tear-off closures). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « frog/leg/emitter.dart ('k') | tests/language/language-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/namer.dart
diff --git a/frog/leg/namer.dart b/frog/leg/namer.dart
index 1355d1ecd671db65682a455a54ba726be7b0f09b..aa2265375b80b98001201ff357c79b32f06f3f4c 100644
--- a/frog/leg/namer.dart
+++ b/frog/leg/namer.dart
@@ -64,6 +64,24 @@ class Namer {
return 'get\$$name';
}
+ String getFreshGlobalName(String proposedName) {
+ int usedCount = usedGlobals[proposedName];
+ if (usedCount === null) {
+ // No element with this name has been used before.
+ usedGlobals[proposedName] = 1;
+ return proposedName;
+ } else {
+ // Not the first time we see this name. Append a number to make it unique.
+ String name;
+ do {
+ usedCount++;
+ name = '$proposedName$usedCount';
+ } while (usedGlobals[name] !== null);
+ usedGlobals[proposedName] = usedCount;
+ return name;
+ }
+ }
+
/**
* Returns a preferred JS-id for the given top-level or static element.
* The returned id is guaranteed to be a valid JS-id.
@@ -110,7 +128,6 @@ class Namer {
*/
String getName(Element element) {
if (element.isInstanceMember()) {
- SourceString name;
if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) {
ConstructorBodyElement bodyElement = element;
SourceString name = bodyElement.constructor.name;
@@ -144,25 +161,9 @@ class Namer {
case ElementKind.FIELD:
case ElementKind.GETTER:
case ElementKind.SETTER:
- // We need to make sure the name is unique.
- int usedCount = usedGlobals[guess];
- if (usedCount === null) {
- // No element with this name has been used before.
- usedGlobals[guess] = 1;
- globals[element] = guess;
- return guess;
- } else {
- // Not the first time we see an element with this name. Append a
- // number to make it unique.
- String name;
- do {
- usedCount++;
- name = '$guess$usedCount';
- } while (usedGlobals[name] !== null);
- usedGlobals[guess] = usedCount;
- globals[element] = name;
- return name;
- }
+ String result = getFreshGlobalName(guess);
+ globals[element] = result;
+ return result;
default:
compiler.internalError('getName for unknown kind: ${element.kind}',
« no previous file with comments | « frog/leg/emitter.dart ('k') | tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698