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 // TODO(ahe): This class is simply wrong. This backend should use | 7 // TODO(ahe): This class is simply wrong. This backend should use |
8 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
9 // TreeElements>] is what is needed. | 9 // TreeElements>] is what is needed. |
10 class ElementAst { | 10 class ElementAst { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 * used in signatures, as/is operators or in super clauses | 588 * used in signatures, as/is operators or in super clauses |
589 * (just to name a few). Retraverse AST to pick those up. | 589 * (just to name a few). Retraverse AST to pick those up. |
590 */ | 590 */ |
591 class ReferencedElementCollector extends Visitor { | 591 class ReferencedElementCollector extends Visitor { |
592 final Compiler compiler; | 592 final Compiler compiler; |
593 final Element rootElement; | 593 final Element rootElement; |
594 final TreeElements treeElements; | 594 final TreeElements treeElements; |
595 final newTypedefElementCallback; | 595 final newTypedefElementCallback; |
596 final newClassElementCallback; | 596 final newClassElementCallback; |
597 | 597 |
598 ReferencedElementCollector( | 598 ReferencedElementCollector(this.compiler, |
599 this.compiler, | 599 Element rootElement, |
600 Element rootElement, this.treeElements, | 600 this.treeElements, |
601 this.newTypedefElementCallback, this.newClassElementCallback) | 601 this.newTypedefElementCallback, |
602 : this.rootElement = (rootElement is VariableElement) | 602 this.newClassElementCallback) |
603 ? (rootElement as VariableElement).variables : rootElement; | 603 : this.rootElement = |
| 604 rootElement is VariableElement ? rootElement.variables : rootElement; |
604 | 605 |
605 visitNode(Node node) { node.visitChildren(this); } | 606 visitNode(Node node) { |
| 607 node.visitChildren(this); |
| 608 } |
606 | 609 |
607 visitTypeAnnotation(TypeAnnotation typeAnnotation) { | 610 visitTypeAnnotation(TypeAnnotation typeAnnotation) { |
608 // We call [resolveReturnType] to allow having 'void'. | 611 // We call [resolveReturnType] to allow having 'void'. |
609 final type = compiler.resolveReturnType(rootElement, typeAnnotation); | 612 final type = compiler.resolveReturnType(rootElement, typeAnnotation); |
610 Element typeElement = type.element; | 613 Element typeElement = type.element; |
611 if (typeElement.isTypedef()) newTypedefElementCallback(typeElement); | 614 if (typeElement.isTypedef()) newTypedefElementCallback(typeElement); |
612 if (typeElement.isClass()) newClassElementCallback(typeElement); | 615 if (typeElement.isClass()) newClassElementCallback(typeElement); |
613 typeAnnotation.visitChildren(this); | 616 typeAnnotation.visitChildren(this); |
614 } | 617 } |
615 | 618 |
(...skipping 13 matching lines...) Expand all Loading... |
629 } | 632 } |
630 | 633 |
631 compareElements(e0, e1) { | 634 compareElements(e0, e1) { |
632 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); | 635 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); |
633 if (result != 0) return result; | 636 if (result != 0) return result; |
634 return compareBy((e) => e.position().charOffset)(e0, e1); | 637 return compareBy((e) => e.position().charOffset)(e0, e1); |
635 } | 638 } |
636 | 639 |
637 List<Element> sortElements(Iterable<Element> elements) => | 640 List<Element> sortElements(Iterable<Element> elements) => |
638 sorted(elements, compareElements); | 641 sorted(elements, compareElements); |
OLD | NEW |