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

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

Issue 10915104: Move namer into javascript backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
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("leg.dart"); 8 #import("leg.dart");
9 #import("scanner/scannerlib.dart"); 9 #import("scanner/scannerlib.dart");
10 #import("tree/tree.dart"); 10 #import("tree/tree.dart");
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 link = link.tail) { 437 link = link.tail) {
438 Node definition = link.head; 438 Node definition = link.head;
439 Element element = elements[definition]; 439 Element element = elements[definition];
440 if (capturedVariableMapping.containsKey(element)) { 440 if (capturedVariableMapping.containsKey(element)) {
441 result.add(element); 441 result.add(element);
442 }; 442 };
443 } 443 }
444 scopeData.boxedLoopVariables = result; 444 scopeData.boxedLoopVariables = result;
445 } 445 }
446 446
447 /** Returns a non-unique name for the given closure element. */
448 String closureName(Element element) {
floitsch 2012/09/05 21:27:46 code directly copied from the Namer. The name giv
449 List<String> parts = <String>[];
450 SourceString ownName = element.name;
451 if (ownName == null || ownName.stringValue == "") {
452 parts.add("anon");
453 } else {
454 parts.add(ownName.slowToString());
455 }
456 for (Element enclosingElement = element.enclosingElement;
457 enclosingElement != null &&
458 (enclosingElement.kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY
459 || enclosingElement.kind === ElementKind.CLASS
460 || enclosingElement.kind === ElementKind.FUNCTION
461 || enclosingElement.kind === ElementKind.GETTER
462 || enclosingElement.kind === ElementKind.SETTER);
463 enclosingElement = enclosingElement.enclosingElement) {
464 SourceString surroundingName = enclosingElement.name;
465 if (surroundingName != null) {
466 String surroundingNameString = surroundingName.slowToString();
467 if (surroundingNameString != "") parts.add(surroundingNameString);
468 }
469 }
470 // Invert the parts.
471 for (int i = 0, j = parts.length - 1; i < j; i++, j--) {
472 var tmp = parts[i];
473 parts[i] = parts[j];
474 parts[j] = tmp;
475 }
476 return Strings.join(parts, "_");
477 }
478
447 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) { 479 ClosureClassMap globalizeClosure(FunctionExpression node, Element element) {
448 SourceString closureName = 480 SourceString closureName = new SourceString(closureName(element));
449 new SourceString(compiler.namer.closureName(element));
450 ClassElement globalizedElement = new ClosureClassElement( 481 ClassElement globalizedElement = new ClosureClassElement(
451 closureName, compiler, element, element.getCompilationUnit()); 482 closureName, compiler, element, element.getCompilationUnit());
452 FunctionElement callElement = 483 FunctionElement callElement =
453 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, 484 new FunctionElement.from(Compiler.CALL_OPERATOR_NAME,
454 element, 485 element,
455 globalizedElement); 486 globalizedElement);
456 globalizedElement.backendMembers = 487 globalizedElement.backendMembers =
457 const EmptyLink<Element>().prepend(callElement); 488 const EmptyLink<Element>().prepend(callElement);
458 // The nested function's 'this' is the same as the one for the outer 489 // The nested function's 'this' is the same as the one for the outer
459 // function. It could be [null] if we are inside a static method. 490 // function. It could be [null] if we are inside a static method.
460 Element thisElement = closureData.thisElement; 491 Element thisElement = closureData.thisElement;
461 return new ClosureClassMap(element, globalizedElement, 492 return new ClosureClassMap(element, globalizedElement,
462 callElement, thisElement); 493 callElement, thisElement);
463 } 494 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 } 583 }
553 584
554 visitTryStatement(TryStatement node) { 585 visitTryStatement(TryStatement node) {
555 // TODO(ngeoffray): implement finer grain state. 586 // TODO(ngeoffray): implement finer grain state.
556 bool oldInTryStatement = inTryStatement; 587 bool oldInTryStatement = inTryStatement;
557 inTryStatement = true; 588 inTryStatement = true;
558 node.visitChildren(this); 589 node.visitChildren(this);
559 inTryStatement = oldInTryStatement; 590 inTryStatement = oldInTryStatement;
560 } 591 }
561 } 592 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/compiler.dart » ('j') | lib/compiler/implementation/compiler.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698