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

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: 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
Index: frog/leg/namer.dart
diff --git a/frog/leg/namer.dart b/frog/leg/namer.dart
index 1355d1ecd671db65682a455a54ba726be7b0f09b..dc10c75994e35ca842b19d87eb3d03d7fccf5055 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.
@@ -96,6 +114,11 @@ class Namer {
}
}
+ String _computeFreshGlobalName(Element element) {
ngeoffray 2012/02/16 12:38:46 I would remove this method, it's only called once,
floitsch 2012/02/16 13:43:07 Done.
+ String guess = _computeGuess(element);
+ return getFreshGlobalName(guess);
+ }
+
String getBailoutName(Element element) {
return '${getName(element)}\$bailout';
}
@@ -131,12 +154,11 @@ class Namer {
String cached = globals[element];
if (cached !== null) return cached;
- String guess = _computeGuess(element);
switch (element.kind) {
case ElementKind.VARIABLE:
case ElementKind.PARAMETER:
// The name is not guaranteed to be unique.
- return guess;
+ return _computeGuess(element);
case ElementKind.GENERATIVE_CONSTRUCTOR:
case ElementKind.FUNCTION:
@@ -144,25 +166,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 = _computeFreshGlobalName(element);
+ globals[element] = result;
+ return result;
default:
compiler.internalError('getName for unknown kind: ${element.kind}',

Powered by Google App Engine
This is Rietveld 408576698