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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/closure.dart

Issue 10905211: Clean up operator names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library closureToClassMapper; 5 library closureToClassMapper;
6 6
7 import "elements/elements.dart"; 7 import "elements/elements.dart";
8 import "dart2jslib.dart"; 8 import "dart2jslib.dart";
9 import "tree/tree.dart"; 9 import "tree/tree.dart";
10 import "util/util.dart"; 10 import "util/util.dart";
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 Element element = elements[definition]; 472 Element element = elements[definition];
473 if (capturedVariableMapping.containsKey(element)) { 473 if (capturedVariableMapping.containsKey(element)) {
474 result.add(element); 474 result.add(element);
475 }; 475 };
476 } 476 }
477 scopeData.boxedLoopVariables = result; 477 scopeData.boxedLoopVariables = result;
478 } 478 }
479 479
480 /** Returns a non-unique name for the given closure element. */ 480 /** Returns a non-unique name for the given closure element. */
481 String closureName(Element element) { 481 String closureName(Element element) {
482 List<String> parts = <String>[]; 482 Link<String> parts = const Link<String>();
483 SourceString ownName = element.name; 483 SourceString ownName = element.name;
484 if (ownName == null || ownName.stringValue == "") { 484 if (ownName == null || ownName.stringValue == "") {
485 parts.add("anon"); 485 parts = parts.prepend("anon");
486 } else { 486 } else {
487 parts.add(ownName.slowToString()); 487 parts = parts.prepend(ownName.slowToString());
488 } 488 }
489 for (Element enclosingElement = element.enclosingElement; 489 for (Element enclosingElement = element.enclosingElement;
490 enclosingElement != null && 490 enclosingElement != null &&
491 (identical(enclosingElement.kind, ElementKind.GENERATIVE_CONSTRUCTO R_BODY) 491 (identical(enclosingElement.kind,
492 ElementKind.GENERATIVE_CONSTRUCTOR_BODY)
492 || identical(enclosingElement.kind, ElementKind.CLASS) 493 || identical(enclosingElement.kind, ElementKind.CLASS)
493 || identical(enclosingElement.kind, ElementKind.FUNCTION) 494 || identical(enclosingElement.kind, ElementKind.FUNCTION)
494 || identical(enclosingElement.kind, ElementKind.GETTER) 495 || identical(enclosingElement.kind, ElementKind.GETTER)
495 || identical(enclosingElement.kind, ElementKind.SETTER)); 496 || identical(enclosingElement.kind, ElementKind.SETTER));
496 enclosingElement = enclosingElement.enclosingElement) { 497 enclosingElement = enclosingElement.enclosingElement) {
497 SourceString surroundingName = enclosingElement.name; 498 SourceString surroundingName =
498 if (surroundingName != null) { 499 Elements.operatorNameToIdentifier(enclosingElement.name);
499 String surroundingNameString = surroundingName.slowToString(); 500 parts = parts.prepend(surroundingName.slowToString());
500 if (surroundingNameString != "") parts.add(surroundingNameString);
501 }
502 } 501 }
503 // Invert the parts. 502 StringBuffer sb = new StringBuffer();
504 for (int i = 0, j = parts.length - 1; i < j; i++, j--) { 503 parts.printOn(sb, '_');
505 var tmp = parts[i]; 504 return sb.toString();
506 parts[i] = parts[j];
507 parts[j] = tmp;
508 }
509 return Strings.join(parts, "_");
510 } 505 }
511 506
512 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) { 507 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) {
513 SourceString closureName = new SourceString(closureName(element)); 508 SourceString closureName = new SourceString(closureName(element));
514 ClassElement globalizedElement = new ClosureClassElement( 509 ClassElement globalizedElement = new ClosureClassElement(
515 closureName, compiler, element, element.getCompilationUnit()); 510 closureName, compiler, element, element.getCompilationUnit());
516 FunctionElement callElement = 511 FunctionElement callElement =
517 new FunctionElement.from(Compiler.CALL_OPERATOR_NAME, 512 new FunctionElement.from(Compiler.CALL_OPERATOR_NAME,
518 element, 513 element,
519 globalizedElement); 514 globalizedElement);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 615 }
621 616
622 visitTryStatement(TryStatement node) { 617 visitTryStatement(TryStatement node) {
623 // TODO(ngeoffray): implement finer grain state. 618 // TODO(ngeoffray): implement finer grain state.
624 bool oldInTryStatement = inTryStatement; 619 bool oldInTryStatement = inTryStatement;
625 inTryStatement = true; 620 inTryStatement = true;
626 node.visitChildren(this); 621 node.visitChildren(this);
627 inTryStatement = oldInTryStatement; 622 inTryStatement = oldInTryStatement;
628 } 623 }
629 } 624 }
OLDNEW
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698