| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 deferred_load; | 5 library deferred_load; |
| 6 | 6 |
| 7 import 'dart:uri' | 7 import 'dart:uri' |
| 8 show Uri; | 8 show Uri; |
| 9 | 9 |
| 10 import 'dart:collection' | 10 import 'dart:collection' |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 }); | 157 }); |
| 158 } | 158 } |
| 159 | 159 |
| 160 /// Returns all elements in the tree map of [element], but not the | 160 /// Returns all elements in the tree map of [element], but not the |
| 161 /// transitive closure. | 161 /// transitive closure. |
| 162 Set<Element> allElementsResolvedFrom(Element element) { | 162 Set<Element> allElementsResolvedFrom(Element element) { |
| 163 element = element.implementation; | 163 element = element.implementation; |
| 164 Set<Element> result = new LinkedHashSet<Element>(); | 164 Set<Element> result = new LinkedHashSet<Element>(); |
| 165 if (element.isGenerativeConstructor()) { | 165 if (element.isGenerativeConstructor()) { |
| 166 // When instantiating a class, we record a reference to the | 166 // When instantiating a class, we record a reference to the |
| 167 // constructor, not the class itself. | 167 // constructor, not the class itself. We must add all the |
| 168 element = element.getEnclosingClass().implementation; | 168 // instance members of the constructor's class (see below). |
| 169 result.addAll( |
| 170 allElementsResolvedFrom(element.getEnclosingClass().implementation)); |
| 169 } | 171 } |
| 170 if (element.isClass()) { | 172 if (element.isClass()) { |
| 171 // If we see a class, add everything its instance members refer | 173 // If we see a class, add everything its instance members refer |
| 172 // to. Static members are not relevant. | 174 // to. Static members are not relevant. |
| 173 ClassElement cls = element.declaration; | 175 ClassElement cls = element.declaration; |
| 174 cls.forEachLocalMember((Element e) { | 176 cls.forEachLocalMember((Element e) { |
| 175 if (!e.isInstanceMember()) return; | 177 if (!e.isInstanceMember()) return; |
| 176 result.addAll(DependencyCollector.collect(e.implementation, compiler)); | 178 result.addAll(DependencyCollector.collect(e.implementation, compiler)); |
| 177 }); | 179 }); |
| 178 if (cls.implementation != cls) { | 180 if (cls.implementation != cls) { |
| 179 // TODO(ahe): Why doesn't ClassElement.forEachLocalMember do this? | 181 // TODO(ahe): Why doesn't ClassElement.forEachLocalMember do this? |
| 180 cls.implementation.forEachLocalMember((Element e) { | 182 cls.implementation.forEachLocalMember((Element e) { |
| 181 if (!e.isInstanceMember()) return; | 183 if (!e.isInstanceMember()) return; |
| 182 result.addAll(DependencyCollector.collect(e.implementation, | 184 result.addAll(DependencyCollector.collect(e.implementation, |
| 183 compiler)); | 185 compiler)); |
| 184 }); | 186 }); |
| 185 } | 187 } |
| 186 for (var type in cls.allSupertypes) { | 188 for (var type in cls.allSupertypes) { |
| 187 result.add(type.element.implementation); | 189 result.add(type.element.implementation); |
| 188 } | 190 } |
| 189 result.add(cls.implementation); | 191 result.add(cls.implementation); |
| 190 } else if (Elements.isStaticOrTopLevel(element)) { | 192 } else if (Elements.isStaticOrTopLevel(element) |
| 193 || element.isConstructor()) { |
| 191 result.addAll(DependencyCollector.collect(element, compiler)); | 194 result.addAll(DependencyCollector.collect(element, compiler)); |
| 192 } | 195 } |
| 193 // Other elements, in particular instance members, are ignored as | 196 // Other elements, in particular instance members, are ignored as |
| 194 // they are processed as part of the class. | 197 // they are processed as part of the class. |
| 195 return result; | 198 return result; |
| 196 } | 199 } |
| 197 | 200 |
| 198 void addTransitiveClosureTo(Set<Element> elements) { | 201 void addTransitiveClosureTo(Set<Element> elements) { |
| 199 Set<Element> workSet = new LinkedHashSet.from(elements); | 202 Set<Element> workSet = new LinkedHashSet.from(elements); |
| 200 Set<Element> closure = new LinkedHashSet<Element>(); | 203 Set<Element> closure = new LinkedHashSet<Element>(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 class DependencyCollector extends Visitor { | 244 class DependencyCollector extends Visitor { |
| 242 final Set<Element> dependencies = new LinkedHashSet<Element>(); | 245 final Set<Element> dependencies = new LinkedHashSet<Element>(); |
| 243 final TreeElements elements; | 246 final TreeElements elements; |
| 244 final Compiler compiler; | 247 final Compiler compiler; |
| 245 | 248 |
| 246 DependencyCollector(this.elements, this.compiler); | 249 DependencyCollector(this.elements, this.compiler); |
| 247 | 250 |
| 248 visitNode(Node node) { | 251 visitNode(Node node) { |
| 249 node.visitChildren(this); | 252 node.visitChildren(this); |
| 250 Element dependency = elements[node]; | 253 Element dependency = elements[node]; |
| 251 if (dependency == null) return; | 254 if (Elements.isUnresolved(dependency)) return; |
| 252 dependencies.add(dependency.implementation); | 255 dependencies.add(dependency.implementation); |
| 253 } | 256 } |
| 254 | 257 |
| 255 static Set<Element> collect(Element element, Compiler compiler) { | 258 static Set<Element> collect(Element element, Compiler compiler) { |
| 256 TreeElements elements = | 259 TreeElements elements = |
| 257 compiler.enqueuer.resolution.getCachedElements(element); | 260 compiler.enqueuer.resolution.getCachedElements(element); |
| 258 if (elements == null) return new LinkedHashSet<Element>(); | 261 if (elements == null) return new LinkedHashSet<Element>(); |
| 259 Node node = element.parseNode(compiler); | 262 Node node = element.parseNode(compiler); |
| 260 var collector = new DependencyCollector(elements, compiler); | 263 var collector = new DependencyCollector(elements, compiler); |
| 261 node.accept(collector); | 264 node.accept(collector); |
| 262 collector.dependencies.addAll(elements.otherDependencies); | 265 collector.dependencies.addAll(elements.otherDependencies); |
| 263 return collector.dependencies; | 266 return collector.dependencies; |
| 264 } | 267 } |
| 265 } | 268 } |
| OLD | NEW |