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 class LocalPlaceholder implements Hashable { | 5 class LocalPlaceholder implements Hashable { |
6 final String identifier; | 6 final String identifier; |
7 final Set<Node> nodes; | 7 final Set<Node> nodes; |
8 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); | 8 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); |
9 int hashCode() => identifier.hashCode(); | 9 int hashCode() => identifier.hashCode(); |
10 String toString() => | 10 String toString() => |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 void tryMakeMemberPlaceholder(Identifier node) { | 278 void tryMakeMemberPlaceholder(Identifier node) { |
279 assert(node !== null); | 279 assert(node !== null); |
280 if (node.source.isPrivate()) return; | 280 if (node.source.isPrivate()) return; |
281 if (node is Operator) return; | 281 if (node is Operator) return; |
282 final identifier = node.source.slowToString(); | 282 final identifier = node.source.slowToString(); |
283 if (fixedMemberNames.contains(identifier)) return; | 283 if (fixedMemberNames.contains(identifier)) return; |
284 memberPlaceholders.putIfAbsent( | 284 memberPlaceholders.putIfAbsent( |
285 identifier, () => new Set<Identifier>()).add(node); | 285 identifier, () => new Set<Identifier>()).add(node); |
286 } | 286 } |
287 | 287 |
288 void makeTypePlaceholder(Node node, Type type) { | 288 void makeTypePlaceholder(Node node, DartType type) { |
289 makeElementPlaceholder(node, type.element); | 289 makeElementPlaceholder(node, type.element); |
290 } | 290 } |
291 | 291 |
292 void makeOmitDeclarationTypePlaceholder(TypeAnnotation type) { | 292 void makeOmitDeclarationTypePlaceholder(TypeAnnotation type) { |
293 if (type === null) return; | 293 if (type === null) return; |
294 declarationTypePlaceholders.add( | 294 declarationTypePlaceholders.add( |
295 new DeclarationTypePlaceholder(type, false)); | 295 new DeclarationTypePlaceholder(type, false)); |
296 } | 296 } |
297 | 297 |
298 void makeVarDeclarationTypePlaceholder(VariableDefinitions node) { | 298 void makeVarDeclarationTypePlaceholder(VariableDefinitions node) { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 518 } |
519 } | 519 } |
520 | 520 |
521 visitClassNode(ClassNode node) { | 521 visitClassNode(ClassNode node) { |
522 ClassElement classElement = currentElement; | 522 ClassElement classElement = currentElement; |
523 makeElementPlaceholder(node.name, classElement); | 523 makeElementPlaceholder(node.name, classElement); |
524 node.visitChildren(this); | 524 node.visitChildren(this); |
525 if (node.defaultClause !== null) { | 525 if (node.defaultClause !== null) { |
526 // Can't just visit class node's default clause because of the bug in the | 526 // Can't just visit class node's default clause because of the bug in the |
527 // resolver, it just crashes when it meets type variable. | 527 // resolver, it just crashes when it meets type variable. |
528 Type defaultType = classElement.defaultClass; | 528 DartType defaultType = classElement.defaultClass; |
529 assert(defaultType !== null); | 529 assert(defaultType !== null); |
530 makeTypePlaceholder(node.defaultClause.typeName, defaultType); | 530 makeTypePlaceholder(node.defaultClause.typeName, defaultType); |
531 visit(node.defaultClause.typeArguments); | 531 visit(node.defaultClause.typeArguments); |
532 } | 532 } |
533 } | 533 } |
534 | 534 |
535 bool tryResolveAndCollectTypeVariable( | 535 bool tryResolveAndCollectTypeVariable( |
536 TypeDeclarationElement typeDeclaration, Identifier name) { | 536 TypeDeclarationElement typeDeclaration, Identifier name) { |
537 // Hack for case when interface and default class are in different | 537 // Hack for case when interface and default class are in different |
538 // libraries, try to resolve type variable to default class type arg. | 538 // libraries, try to resolve type variable to default class type arg. |
539 // Example: | 539 // Example: |
540 // lib1: interface I<K> default C<K> {...} | 540 // lib1: interface I<K> default C<K> {...} |
541 // lib2: class C<K> {...} | 541 // lib2: class C<K> {...} |
542 if (typeDeclaration is ClassElement | 542 if (typeDeclaration is ClassElement |
543 && (typeDeclaration as ClassElement).defaultClass !== null) { | 543 && (typeDeclaration as ClassElement).defaultClass !== null) { |
544 typeDeclaration = (typeDeclaration as ClassElement).defaultClass.element; | 544 typeDeclaration = (typeDeclaration as ClassElement).defaultClass.element; |
545 } | 545 } |
546 // Another poor man type resolution. | 546 // Another poor man type resolution. |
547 // Find this variable in enclosing type declaration parameters. | 547 // Find this variable in enclosing type declaration parameters. |
548 for (Type type in typeDeclaration.typeVariables) { | 548 for (DartType type in typeDeclaration.typeVariables) { |
549 if (type.name.slowToString() == name.source.slowToString()) { | 549 if (type.name.slowToString() == name.source.slowToString()) { |
550 makeTypePlaceholder(name, type); | 550 makeTypePlaceholder(name, type); |
551 return true; | 551 return true; |
552 } | 552 } |
553 } | 553 } |
554 return false; | 554 return false; |
555 } | 555 } |
556 | 556 |
557 visitTypeVariable(TypeVariable node) { | 557 visitTypeVariable(TypeVariable node) { |
558 assert(currentElement is TypedefElement || currentElement is ClassElement); | 558 assert(currentElement is TypedefElement || currentElement is ClassElement); |
(...skipping 11 matching lines...) Expand all Loading... |
570 | 570 |
571 visitBlock(Block node) { | 571 visitBlock(Block node) { |
572 for (Node statement in node.statements.nodes) { | 572 for (Node statement in node.statements.nodes) { |
573 if (statement is VariableDefinitions) { | 573 if (statement is VariableDefinitions) { |
574 makeVarDeclarationTypePlaceholder(statement); | 574 makeVarDeclarationTypePlaceholder(statement); |
575 } | 575 } |
576 } | 576 } |
577 node.visitChildren(this); | 577 node.visitChildren(this); |
578 } | 578 } |
579 } | 579 } |
OLD | NEW |