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

Unified Diff: dart/lib/compiler/implementation/closure.dart

Issue 10905211: Clean up operator names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 2 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: dart/lib/compiler/implementation/closure.dart
diff --git a/dart/lib/compiler/implementation/closure.dart b/dart/lib/compiler/implementation/closure.dart
index be78e41c919c487ddb13ac78de2c959367e3c7be..c9e263660061b1c25e4859ac12cf3e792837d992 100644
--- a/dart/lib/compiler/implementation/closure.dart
+++ b/dart/lib/compiler/implementation/closure.dart
@@ -483,12 +483,67 @@ class ClosureTranslator extends Visitor {
/** Returns a non-unique name for the given closure element. */
String closureName(Element element) {
- List<String> parts = <String>[];
+ String safeElementName(Element element) {
+ SourceString name = element.name;
+ if (name == null) return "";
+ String value = name.stringValue;
floitsch 2012/10/17 12:13:47 I would just ask if the element is an operator, an
ahe 2012/11/12 13:22:09 I'm using more telling names now.
+ // A valid Dart identifier cannot start with a digit.
+ // Fortunately, operators are always enclosed in a class which
+ // means that the resulting closure name will not start with a
+ // digit.
+ if (value === '==') {
+ return '0';
+ } else if (value === '~') {
+ return '1';
+ } else if (value === '[]') {
+ return '2';
+ } else if (value === '[]=') {
+ return '3';
+ } else if (value === '*') {
+ return '4';
+ } else if (value === '/') {
+ return '5';
+ } else if (value === '%') {
+ return '6';
+ } else if (value === '~/') {
+ return '7';
+ } else if (value === '+') {
+ return '8';
+ } else if (value === '<<') {
+ return '9';
+ } else if (value === '>>>') {
+ return '10';
+ } else if (value === '>>') {
+ return '11';
+ } else if (value === '>=') {
+ return '12';
+ } else if (value === '>') {
+ return '13';
+ } else if (value === '<=') {
+ return '14';
+ } else if (value === '<') {
+ return '15';
+ } else if (value === '&') {
+ return '16';
+ } else if (value === '^') {
+ return '17';
+ } else if (value === '|') {
+ return '18';
+ } else if (value === '-') {
+ return '19';
+ } else if (value === 'unary -') {
+ return '20';
+ } else {
+ return name.slowToString();
+ }
+ }
+
+ Link<String> parts = const Link<String>();
SourceString ownName = element.name;
if (ownName == null || ownName.stringValue == "") {
- parts.add("anon");
+ parts = parts.prepend("anon");
} else {
- parts.add(ownName.slowToString());
+ parts = parts.prepend(ownName.slowToString());
}
for (Element enclosingElement = element.enclosingElement;
enclosingElement != null &&
@@ -498,19 +553,12 @@ class ClosureTranslator extends Visitor {
|| enclosingElement.kind === ElementKind.GETTER
|| enclosingElement.kind === ElementKind.SETTER);
enclosingElement = enclosingElement.enclosingElement) {
- SourceString surroundingName = enclosingElement.name;
- if (surroundingName != null) {
- String surroundingNameString = surroundingName.slowToString();
- if (surroundingNameString != "") parts.add(surroundingNameString);
- }
- }
- // Invert the parts.
- for (int i = 0, j = parts.length - 1; i < j; i++, j--) {
- var tmp = parts[i];
- parts[i] = parts[j];
- parts[j] = tmp;
+ String surroundingName = safeElementName(enclosingElement);
+ if (surroundingName != "") parts = parts.prepend(surroundingName);
floitsch 2012/10/17 12:13:47 NYC: no need to do this test.
ahe 2012/11/12 13:22:09 Done.
}
- return Strings.join(parts, "_");
+ StringBuffer sb = new StringBuffer();
+ parts.printOn(sb, '_');
+ return sb.toString();
}
ClosureClassMap globalizeClosure(FunctionExpression node, Element element) {

Powered by Google App Engine
This is Rietveld 408576698