Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer.src.dart.element.element; | 5 library analyzer.src.dart.element.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| 11 import 'package:analyzer/dart/ast/token.dart'; | 11 import 'package:analyzer/dart/ast/token.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/dart/element/type.dart'; | 13 import 'package:analyzer/dart/element/type.dart'; |
| 14 import 'package:analyzer/dart/element/visitor.dart'; | 14 import 'package:analyzer/dart/element/visitor.dart'; |
| 15 import 'package:analyzer/src/dart/ast/utilities.dart'; | 15 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 16 import 'package:analyzer/src/dart/element/type.dart'; | 16 import 'package:analyzer/src/dart/element/type.dart'; |
| 17 import 'package:analyzer/src/generated/constant.dart' | 17 import 'package:analyzer/src/generated/constant.dart' |
| 18 show DartObject, EvaluationResultImpl; | 18 show DartObject, EvaluationResultImpl; |
| 19 import 'package:analyzer/src/generated/element_handle.dart'; | |
| 19 import 'package:analyzer/src/generated/engine.dart' | 20 import 'package:analyzer/src/generated/engine.dart' |
| 20 show AnalysisContext, AnalysisEngine; | 21 show AnalysisContext, AnalysisEngine; |
| 21 import 'package:analyzer/src/generated/java_core.dart'; | 22 import 'package:analyzer/src/generated/java_core.dart'; |
| 22 import 'package:analyzer/src/generated/java_engine.dart'; | 23 import 'package:analyzer/src/generated/java_engine.dart'; |
| 23 import 'package:analyzer/src/generated/resolver.dart'; | 24 import 'package:analyzer/src/generated/resolver.dart'; |
| 24 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; | 25 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; |
| 25 import 'package:analyzer/src/generated/source.dart'; | 26 import 'package:analyzer/src/generated/source.dart'; |
| 26 import 'package:analyzer/src/generated/utilities_collection.dart'; | 27 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 27 import 'package:analyzer/src/generated/utilities_dart.dart'; | 28 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 28 import 'package:analyzer/src/generated/utilities_general.dart'; | 29 import 'package:analyzer/src/generated/utilities_general.dart'; |
| (...skipping 3229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3258 // The stack of discovered elements | 3259 // The stack of discovered elements |
| 3259 List<LibraryElementImpl> stack = []; | 3260 List<LibraryElementImpl> stack = []; |
| 3260 // For a given library that has not yet been processed by this run of the | 3261 // For a given library that has not yet been processed by this run of the |
| 3261 // algorithm, compute the strongly connected components. | 3262 // algorithm, compute the strongly connected components. |
| 3262 int scc(LibraryElementImpl library) { | 3263 int scc(LibraryElementImpl library) { |
| 3263 int index = counter++; | 3264 int index = counter++; |
| 3264 int root = index; | 3265 int root = index; |
| 3265 indices[library] = index; | 3266 indices[library] = index; |
| 3266 active.add(library); | 3267 active.add(library); |
| 3267 stack.add(library); | 3268 stack.add(library); |
| 3269 LibraryElementImpl getActualLibrary(LibraryElement lib) { | |
| 3270 // TODO(paulberry): this means that computing a library cycle will be | |
| 3271 // expensive for libraries resynthesized from summaries, since it will | |
| 3272 // require fully resynthesizing all the libraries in the cycle as well | |
| 3273 // as any libraries they import or export. Try to find a better way. | |
|
Brian Wilkerson
2016/02/25 20:47:39
Eventually, resynthesis should be lazy, in which c
Paul Berry
2016/02/25 21:08:30
Yes, I hope to do that, but even under the optimis
| |
| 3274 if (lib is LibraryElementHandle) { | |
| 3275 return lib.actualElement; | |
| 3276 } else { | |
| 3277 return lib; | |
| 3278 } | |
| 3279 } | |
| 3268 void recurse(LibraryElementImpl child) { | 3280 void recurse(LibraryElementImpl child) { |
| 3269 if (!indices.containsKey(child)) { | 3281 if (!indices.containsKey(child)) { |
| 3270 // We haven't visited this child yet, so recurse on the child, | 3282 // We haven't visited this child yet, so recurse on the child, |
| 3271 // returning the lowest numbered node reachable from the child. If | 3283 // returning the lowest numbered node reachable from the child. If |
| 3272 // the child can reach a root which is lower numbered than anything | 3284 // the child can reach a root which is lower numbered than anything |
| 3273 // we've reached so far, update the root. | 3285 // we've reached so far, update the root. |
| 3274 root = min(root, scc(child)); | 3286 root = min(root, scc(child)); |
| 3275 } else if (active.contains(child)) { | 3287 } else if (active.contains(child)) { |
| 3276 // The child has been visited, but has not yet been placed into a | 3288 // The child has been visited, but has not yet been placed into a |
| 3277 // component. If the child is higher than anything we've seen so far | 3289 // component. If the child is higher than anything we've seen so far |
| 3278 // update the root appropriately. | 3290 // update the root appropriately. |
| 3279 root = min(root, indices[child]); | 3291 root = min(root, indices[child]); |
| 3280 } | 3292 } |
| 3281 } | 3293 } |
| 3282 // Recurse on all of the children in the import/export graph, filtering | 3294 // Recurse on all of the children in the import/export graph, filtering |
| 3283 // out those for which library cycles have already been computed. | 3295 // out those for which library cycles have already been computed. |
| 3284 library.exportedLibraries | 3296 library.exportedLibraries |
| 3297 .map(getActualLibrary) | |
| 3285 .where((l) => l._libraryCycle == null) | 3298 .where((l) => l._libraryCycle == null) |
| 3286 .forEach(recurse); | 3299 .forEach(recurse); |
| 3287 library.importedLibraries | 3300 library.importedLibraries |
| 3301 .map(getActualLibrary) | |
| 3288 .where((l) => l._libraryCycle == null) | 3302 .where((l) => l._libraryCycle == null) |
| 3289 .forEach(recurse); | 3303 .forEach(recurse); |
| 3290 | 3304 |
| 3291 if (root == index) { | 3305 if (root == index) { |
| 3292 // This is the root of a strongly connected component. | 3306 // This is the root of a strongly connected component. |
| 3293 // Pop the elements, and share the component across all | 3307 // Pop the elements, and share the component across all |
| 3294 // of the elements. | 3308 // of the elements. |
| 3295 List<LibraryElement> component = <LibraryElement>[]; | 3309 List<LibraryElement> component = <LibraryElement>[]; |
| 3296 LibraryElementImpl cur = null; | 3310 LibraryElementImpl cur = null; |
| 3297 do { | 3311 do { |
| (...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4802 | 4816 |
| 4803 @override | 4817 @override |
| 4804 void visitElement(Element element) { | 4818 void visitElement(Element element) { |
| 4805 int offset = element.nameOffset; | 4819 int offset = element.nameOffset; |
| 4806 if (offset != -1) { | 4820 if (offset != -1) { |
| 4807 map[offset] = element; | 4821 map[offset] = element; |
| 4808 } | 4822 } |
| 4809 super.visitElement(element); | 4823 super.visitElement(element); |
| 4810 } | 4824 } |
| 4811 } | 4825 } |
| OLD | NEW |