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

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

Issue 18181009: Make closures in constructor initializers read type variables directly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add VM crash and modify test. Created 7 years, 5 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 "dart2jslib.dart"; 8 import "dart2jslib.dart";
9 import "dart_types.dart"; 9 import "dart_types.dart";
10 import "scanner/scannerlib.dart" show Token; 10 import "scanner/scannerlib.dart" show Token;
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 } 487 }
488 } 488 }
489 } 489 }
490 490
491 visitIdentifier(Identifier node) { 491 visitIdentifier(Identifier node) {
492 if (node.isThis()) { 492 if (node.isThis()) {
493 registerNeedsThis(); 493 registerNeedsThis();
494 } else { 494 } else {
495 Element element = elements[node]; 495 Element element = elements[node];
496 if (element != null && element.kind == ElementKind.TYPE_VARIABLE) { 496 if (element != null && element.kind == ElementKind.TYPE_VARIABLE) {
497 registerNeedsThis(); 497 if (outermostElement.isConstructor()) {
498 useLocal(element);
499 } else {
500 registerNeedsThis();
501 }
498 } 502 }
499 } 503 }
500 node.visitChildren(this); 504 node.visitChildren(this);
501 } 505 }
502 506
503 visitSend(Send node) { 507 visitSend(Send node) {
504 Element element = elements[node]; 508 Element element = elements[node];
505 if (Elements.isLocal(element)) { 509 if (Elements.isLocal(element)) {
506 useLocal(element); 510 useLocal(element);
511 } else if (element != null && element.isTypeVariable()) {
512 TypeVariableElement variable = element;
513 analyzeType(variable.type);
507 } else if (node.receiver == null && 514 } else if (node.receiver == null &&
508 Elements.isInstanceSend(node, elements)) { 515 Elements.isInstanceSend(node, elements)) {
509 registerNeedsThis(); 516 registerNeedsThis();
510 } else if (node.isSuperCall) { 517 } else if (node.isSuperCall) {
511 registerNeedsThis(); 518 registerNeedsThis();
512 } else if (node.isTypeTest || node.isTypeCast) { 519 } else if (node.isTypeTest || node.isTypeCast) {
513 TypeAnnotation annotation = node.typeAnnotationFromIsCheckOrCast; 520 TypeAnnotation annotation = node.typeAnnotationFromIsCheckOrCast;
514 DartType type = elements.getType(annotation); 521 DartType type = elements.getType(annotation);
515 if (type != null && type.containsTypeVariables) { 522 analyzeType(type);
516 registerNeedsThis();
517 }
518 } else if (node.isTypeTest) { 523 } else if (node.isTypeTest) {
519 DartType type = elements.getType(node.typeAnnotationFromIsCheckOrCast); 524 DartType type = elements.getType(node.typeAnnotationFromIsCheckOrCast);
520 analyzeType(type); 525 analyzeType(type);
521 } else if (node.isTypeCast) { 526 } else if (node.isTypeCast) {
522 DartType type = elements.getType(node.arguments.head); 527 DartType type = elements.getType(node.arguments.head);
523 analyzeType(type); 528 analyzeType(type);
524 } 529 }
525 node.visitChildren(this); 530 node.visitChildren(this);
526 } 531 }
527 532
(...skipping 10 matching lines...) Expand all
538 } 543 }
539 544
540 visitNewExpression(NewExpression node) { 545 visitNewExpression(NewExpression node) {
541 DartType type = elements.getType(node); 546 DartType type = elements.getType(node);
542 analyzeType(type); 547 analyzeType(type);
543 node.visitChildren(this); 548 node.visitChildren(this);
544 } 549 }
545 550
546 void analyzeTypeVariables(DartType type) { 551 void analyzeTypeVariables(DartType type) {
547 type.forEachTypeVariable((TypeVariableType typeVariable) { 552 type.forEachTypeVariable((TypeVariableType typeVariable) {
548 useLocal(typeVariable.element);
549 // Field initializers are inlined and access the type variable as 553 // Field initializers are inlined and access the type variable as
550 // normal parameters. 554 // normal parameters.
551 if (!outermostElement.isField()) { 555 if (!outermostElement.isField() &&
556 !outermostElement.isConstructor()) {
552 registerNeedsThis(); 557 registerNeedsThis();
558 } else {
559 useLocal(typeVariable.element);
553 } 560 }
554 }); 561 });
555 } 562 }
556 563
557 void analyzeType(DartType type) { 564 void analyzeType(DartType type) {
558 // TODO(johnniwinther): Find out why this can be null. 565 // TODO(johnniwinther): Find out why this can be null.
559 if (type == null) return; 566 if (type == null) return;
560 if (outermostElement.isMember() && 567 if (outermostElement.isMember() &&
561 compiler.backend.classNeedsRti(outermostElement.getEnclosingClass())) { 568 compiler.backend.classNeedsRti(outermostElement.getEnclosingClass())) {
562 if (outermostElement.isConstructor() || 569 if (outermostElement.isConstructor() ||
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 } 807 }
801 808
802 visitTryStatement(TryStatement node) { 809 visitTryStatement(TryStatement node) {
803 // TODO(ngeoffray): implement finer grain state. 810 // TODO(ngeoffray): implement finer grain state.
804 bool oldInTryStatement = inTryStatement; 811 bool oldInTryStatement = inTryStatement;
805 inTryStatement = true; 812 inTryStatement = true;
806 node.visitChildren(this); 813 node.visitChildren(this);
807 inTryStatement = oldInTryStatement; 814 inTryStatement = oldInTryStatement;
808 } 815 }
809 } 816 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698