OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Tracks the shape of the import/export graph and dependencies between files. | 5 /// Tracks the shape of the import/export graph and dependencies between files. |
6 | 6 |
7 import 'dart:collection' show HashSet, HashMap; | 7 import 'dart:collection' show HashSet, HashMap; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart' show parseDirectives; | 9 import 'package:analyzer/analyzer.dart' show parseDirectives; |
10 import 'package:analyzer/src/generated/ast.dart' | 10 import 'package:analyzer/src/generated/ast.dart' |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 void clearSummary() {} | 149 void clearSummary() {} |
150 | 150 |
151 void saveUpdatedContents() {} | 151 void saveUpdatedContents() {} |
152 | 152 |
153 String toString() { | 153 String toString() { |
154 var simpleUri = uri.scheme == 'file' ? path.relative(uri.path) : "$uri"; | 154 var simpleUri = uri.scheme == 'file' ? path.relative(uri.path) : "$uri"; |
155 return '[$runtimeType: $simpleUri]'; | 155 return '[$runtimeType: $simpleUri]'; |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
| 159 /// A unique node representing all entry points in the graph. This is just for |
| 160 /// graph algorthm convenience. |
| 161 class EntryNode extends SourceNode { |
| 162 final Iterable<SourceNode> entryPoints; |
| 163 |
| 164 @override |
| 165 Iterable<SourceNode> get allDeps => entryPoints; |
| 166 |
| 167 @override |
| 168 Iterable<SourceNode> get depsWithoutParts => entryPoints; |
| 169 |
| 170 EntryNode(SourceGraph graph, Uri uri, Iterable<SourceNode> nodes) |
| 171 : entryPoints = nodes, |
| 172 super(graph, uri, null); |
| 173 } |
| 174 |
159 /// A node representing an entry HTML source file. | 175 /// A node representing an entry HTML source file. |
160 class HtmlSourceNode extends SourceNode { | 176 class HtmlSourceNode extends SourceNode { |
161 /// Resources included by default on any application. | 177 /// Resources included by default on any application. |
162 final runtimeDeps; | 178 final runtimeDeps; |
163 | 179 |
164 /// Libraries referred to via script tags. | 180 /// Libraries referred to via script tags. |
165 Set<DartSourceNode> scripts = new Set<DartSourceNode>(); | 181 Set<DartSourceNode> scripts = new Set<DartSourceNode>(); |
166 | 182 |
167 /// Link-rel stylesheets, images, and other specified files. | 183 /// Link-rel stylesheets, images, and other specified files. |
168 Set<SourceNode> resources = new Set<SourceNode>(); | 184 Set<SourceNode> resources = new Set<SourceNode>(); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 // cases anways require using summaries to understand what parts of the public | 475 // cases anways require using summaries to understand what parts of the public |
460 // API may be affected by transitive changes. The re-export case is just one | 476 // API may be affected by transitive changes. The re-export case is just one |
461 // of those transitive cases, but is not sufficient. See | 477 // of those transitive cases, but is not sufficient. See |
462 // https://github.com/dart-lang/dev_compiler/issues/76 | 478 // https://github.com/dart-lang/dev_compiler/issues/76 |
463 var apiChangeDetected = new HashSet<SourceNode>(); | 479 var apiChangeDetected = new HashSet<SourceNode>(); |
464 bool htmlNeedsRebuild = false; | 480 bool htmlNeedsRebuild = false; |
465 | 481 |
466 bool shouldBuildNode(SourceNode n) { | 482 bool shouldBuildNode(SourceNode n) { |
467 if (n.needsRebuild) return true; | 483 if (n.needsRebuild) return true; |
468 if (n is HtmlSourceNode) return htmlNeedsRebuild; | 484 if (n is HtmlSourceNode) return htmlNeedsRebuild; |
469 if (n is ResourceSourceNode) return false; | 485 if (n is ResourceSourceNode || n is EntryNode) return false; |
470 return (n as DartSourceNode) | 486 return (n as DartSourceNode) |
471 .imports | 487 .imports |
472 .any((i) => apiChangeDetected.contains(i)); | 488 .any((i) => apiChangeDetected.contains(i)); |
473 } | 489 } |
474 | 490 |
475 visitInPostOrder(start, (n) { | 491 visitInPostOrder(start, (n) { |
476 if (n.structureChanged) htmlNeedsRebuild = true; | 492 if (n.structureChanged) htmlNeedsRebuild = true; |
477 if (shouldBuildNode(n)) { | 493 if (shouldBuildNode(n)) { |
478 var oldHash = n.cachingHash; | 494 var oldHash = n.cachingHash; |
479 if (build(n)) apiChangeDetected.add(n); | 495 if (build(n)) apiChangeDetected.add(n); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 var deps = includeParts ? node.allDeps : node.depsWithoutParts; | 534 var deps = includeParts ? node.allDeps : node.depsWithoutParts; |
519 deps.forEach(helper); | 535 deps.forEach(helper); |
520 action(node); | 536 action(node); |
521 } | 537 } |
522 helper(start); | 538 helper(start); |
523 } | 539 } |
524 | 540 |
525 bool _same(Set a, Set b) => a.length == b.length && a.containsAll(b); | 541 bool _same(Set a, Set b) => a.length == b.length && a.containsAll(b); |
526 | 542 |
527 final _log = new Logger('dev_compiler.dependency_graph'); | 543 final _log = new Logger('dev_compiler.dependency_graph'); |
OLD | NEW |