| 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 DartBackend extends Backend { | 5 class DartBackend extends Backend { |
| 6 final List<CompilerTask> tasks; | 6 final List<CompilerTask> tasks; |
| 7 final UnparseValidator unparseValidator; | 7 final UnparseValidator unparseValidator; |
| 8 | 8 |
| 9 Map<Element, TreeElements> get resolvedElements() => | 9 Map<Element, TreeElements> get resolvedElements() => |
| 10 compiler.enqueuer.resolution.resolvedElements; | 10 compiler.enqueuer.resolution.resolvedElements; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 /** | 126 /** |
| 127 * Some elements are not recorded by resolver now, | 127 * Some elements are not recorded by resolver now, |
| 128 * for example, typedefs or classes which are only | 128 * for example, typedefs or classes which are only |
| 129 * used in signatures, as/is operators or in super clauses | 129 * used in signatures, as/is operators or in super clauses |
| 130 * (just to name a few). Retraverse AST to pick those up. | 130 * (just to name a few). Retraverse AST to pick those up. |
| 131 */ | 131 */ |
| 132 class ReferencedElementCollector extends AbstractVisitor { | 132 class ReferencedElementCollector extends AbstractVisitor { |
| 133 final Compiler compiler; | 133 final Compiler compiler; |
| 134 final Element element; | 134 final Element rootElement; |
| 135 final TreeElements treeElements; | 135 final TreeElements treeElements; |
| 136 final Set<TypedefElement> typedefs; | 136 final Set<TypedefElement> typedefs; |
| 137 final Set<ClassElement> classes; | 137 final Set<ClassElement> classes; |
| 138 | 138 |
| 139 ReferencedElementCollector( | 139 ReferencedElementCollector( |
| 140 this.compiler, | 140 this.compiler, |
| 141 this.element, this.treeElements, | 141 this.rootElement, this.treeElements, |
| 142 this.typedefs, this.classes); | 142 this.typedefs, this.classes); |
| 143 | 143 |
| 144 void collectElement(Element element) { |
| 145 new ReferencedElementCollector( |
| 146 compiler, element, new TreeElementMapping(), typedefs, classes) |
| 147 .collect(); |
| 148 } |
| 149 |
| 144 visitNode(Node node) { node.visitChildren(this); } | 150 visitNode(Node node) { node.visitChildren(this); } |
| 145 | 151 |
| 146 visitTypeAnnotation(TypeAnnotation typeAnnotation) { | 152 visitTypeAnnotation(TypeAnnotation typeAnnotation) { |
| 147 final type = compiler.resolveTypeAnnotation(element, typeAnnotation); | 153 final type = compiler.resolveTypeAnnotation(rootElement, typeAnnotation); |
| 148 Element typeElement = type.element; | 154 Element typeElement = type.element; |
| 149 if (typeElement.isTypedef() && !typedefs.contains(typeElement)) { | 155 if (typeElement.isTypedef() && !typedefs.contains(typeElement)) { |
| 150 typedefs.add(typeElement); | 156 typedefs.add(typeElement); |
| 151 new ReferencedElementCollector( | 157 collectElement(typeElement); |
| 152 compiler, typeElement, new TreeElementMapping(), typedefs, classes) | |
| 153 .collect(); | |
| 154 } | 158 } |
| 155 if (typeElement.isClass()) classes.add(typeElement); | 159 if (typeElement.isClass() && !classes.contains(typeElement)) { |
| 160 classes.add(typeElement); |
| 161 collectElement(typeElement); |
| 162 } |
| 156 typeAnnotation.visitChildren(this); | 163 typeAnnotation.visitChildren(this); |
| 157 } | 164 } |
| 158 | 165 |
| 159 void collect() { | 166 void collect() { |
| 160 compiler.withCurrentElement(element, () { | 167 compiler.withCurrentElement(rootElement, () { |
| 161 element.parseNode(compiler).accept(this); | 168 rootElement.parseNode(compiler).accept(this); |
| 162 }); | 169 }); |
| 163 } | 170 } |
| 164 } | 171 } |
| OLD | NEW |