OLD | NEW |
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 part of dart_backend; | 5 part of dart_backend; |
6 | 6 |
7 class LocalPlaceholder { | 7 class LocalPlaceholder { |
8 final String identifier; | 8 final String identifier; |
9 final Set<Node> nodes; | 9 final Set<Node> nodes; |
10 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); | 10 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 makeOmitDeclarationTypePlaceholder( | 565 makeOmitDeclarationTypePlaceholder( |
566 parameter.asVariableDefinitions().type); | 566 parameter.asVariableDefinitions().type); |
567 } | 567 } |
568 } | 568 } |
569 } | 569 } |
570 | 570 |
571 visitClassNode(ClassNode node) { | 571 visitClassNode(ClassNode node) { |
572 ClassElement classElement = currentElement; | 572 ClassElement classElement = currentElement; |
573 makeElementPlaceholder(node.name, classElement); | 573 makeElementPlaceholder(node.name, classElement); |
574 node.visitChildren(this); | 574 node.visitChildren(this); |
575 if (node.defaultClause != null) { | |
576 // Can't just visit class node's default clause because of the bug in the | |
577 // resolver, it just crashes when it meets type variable. | |
578 DartType defaultType = classElement.defaultClass; | |
579 assert(defaultType != null); | |
580 makeTypePlaceholder(node.defaultClause.typeName, defaultType); | |
581 visit(node.defaultClause.typeArguments); | |
582 } | |
583 } | 575 } |
584 | 576 |
585 visitNamedMixinApplication(NamedMixinApplication node) { | 577 visitNamedMixinApplication(NamedMixinApplication node) { |
586 ClassElement classElement = currentElement; | 578 ClassElement classElement = currentElement; |
587 makeElementPlaceholder(node.name, classElement); | 579 makeElementPlaceholder(node.name, classElement); |
588 node.visitChildren(this); | 580 node.visitChildren(this); |
589 } | 581 } |
590 | 582 |
591 bool tryResolveAndCollectTypeVariable( | 583 bool tryResolveAndCollectTypeVariable( |
592 TypeDeclarationElement typeDeclaration, Identifier name) { | 584 TypeDeclarationElement typeDeclaration, Identifier name) { |
593 // Hack for case when interface and default class are in different | |
594 // libraries, try to resolve type variable to default class type arg. | |
595 // Example: | |
596 // lib1: interface I<K> default C<K> {...} | |
597 // lib2: class C<K> {...} | |
598 if (typeDeclaration is ClassElement | |
599 && (typeDeclaration as ClassElement).defaultClass != null) { | |
600 typeDeclaration = (typeDeclaration as ClassElement).defaultClass.element; | |
601 } | |
602 // Another poor man type resolution. | 585 // Another poor man type resolution. |
603 // Find this variable in enclosing type declaration parameters. | 586 // Find this variable in enclosing type declaration parameters. |
604 for (DartType type in typeDeclaration.typeVariables) { | 587 for (DartType type in typeDeclaration.typeVariables) { |
605 if (type.name.slowToString() == name.source.slowToString()) { | 588 if (type.name.slowToString() == name.source.slowToString()) { |
606 makeTypePlaceholder(name, type); | 589 makeTypePlaceholder(name, type); |
607 return true; | 590 return true; |
608 } | 591 } |
609 } | 592 } |
610 return false; | 593 return false; |
611 } | 594 } |
(...skipping 14 matching lines...) Expand all Loading... |
626 | 609 |
627 visitBlock(Block node) { | 610 visitBlock(Block node) { |
628 for (Node statement in node.statements.nodes) { | 611 for (Node statement in node.statements.nodes) { |
629 if (statement is VariableDefinitions) { | 612 if (statement is VariableDefinitions) { |
630 makeVarDeclarationTypePlaceholder(statement); | 613 makeVarDeclarationTypePlaceholder(statement); |
631 } | 614 } |
632 } | 615 } |
633 node.visitChildren(this); | 616 node.visitChildren(this); |
634 } | 617 } |
635 } | 618 } |
OLD | NEW |