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 deferred_load; | 5 library deferred_load; |
6 | 6 |
7 import 'dart2jslib.dart' show | 7 import 'dart2jslib.dart' show |
8 Backend, | 8 Backend, |
9 Compiler, | 9 Compiler, |
10 CompilerTask, | 10 CompilerTask, |
(...skipping 18 matching lines...) Expand all Loading... |
29 FunctionElement, | 29 FunctionElement, |
30 LibraryElement, | 30 LibraryElement, |
31 MetadataAnnotation, | 31 MetadataAnnotation, |
32 ScopeContainerElement, | 32 ScopeContainerElement, |
33 PrefixElement, | 33 PrefixElement, |
34 VoidElement, | 34 VoidElement, |
35 TypedefElement, | 35 TypedefElement, |
36 AstElement; | 36 AstElement; |
37 | 37 |
38 import 'util/util.dart' show | 38 import 'util/util.dart' show |
39 Link; | 39 Link, makeUnique; |
40 | 40 |
41 import 'util/setlet.dart' show | 41 import 'util/setlet.dart' show |
42 Setlet; | 42 Setlet; |
43 | 43 |
44 import 'tree/tree.dart' show | 44 import 'tree/tree.dart' show |
45 LibraryTag, | 45 LibraryTag, |
46 Node, | 46 Node, |
47 NewExpression, | 47 NewExpression, |
48 Import, | 48 Import, |
49 LibraryDependency, | 49 LibraryDependency, |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 } | 520 } |
521 } | 521 } |
522 } | 522 } |
523 | 523 |
524 /// Computes a unique string for the name field for each outputUnit. | 524 /// Computes a unique string for the name field for each outputUnit. |
525 /// | 525 /// |
526 /// Also sets up the [hunksToLoad] mapping. | 526 /// Also sets up the [hunksToLoad] mapping. |
527 void _assignNamesToOutputUnits(Set<OutputUnit> allOutputUnits) { | 527 void _assignNamesToOutputUnits(Set<OutputUnit> allOutputUnits) { |
528 Set<String> usedImportNames = new Set<String>(); | 528 Set<String> usedImportNames = new Set<String>(); |
529 | 529 |
530 // Returns suggestedName if it is not in usedNames. Otherwise concatenates | |
531 // the smallest number that makes it not appear in usedNames. | |
532 // Adds the result to usedNames. | |
533 String makeUnique(String suggestedName, Set<String> usedNames) { | |
534 String result = suggestedName; | |
535 if (usedNames.contains(suggestedName)) { | |
536 int counter = 0; | |
537 while (usedNames.contains(result)) { | |
538 counter++; | |
539 result = "$suggestedName$counter"; | |
540 } | |
541 } | |
542 usedNames.add(result); | |
543 return result; | |
544 } | |
545 | |
546 // Finds the first argument to the [DeferredLibrary] annotation | 530 // Finds the first argument to the [DeferredLibrary] annotation |
547 void computeImportDeferName(Import import) { | 531 void computeImportDeferName(Import import) { |
548 String result; | 532 String result; |
549 if (import == _fakeMainImport) { | 533 if (import == _fakeMainImport) { |
550 result = "main"; | 534 result = "main"; |
551 } else if (import.isDeferred) { | 535 } else if (import.isDeferred) { |
552 result = import.prefix.toString(); | 536 result = import.prefix.toString(); |
553 } else { | 537 } else { |
554 Link<MetadataAnnotation> metadatas = import.metadata; | 538 Link<MetadataAnnotation> metadatas = import.metadata; |
555 assert(metadatas != null); | 539 assert(metadatas != null); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 Element maybePrefix = elements[identifier]; | 787 Element maybePrefix = elements[identifier]; |
804 if (maybePrefix != null && maybePrefix.isPrefix) { | 788 if (maybePrefix != null && maybePrefix.isPrefix) { |
805 PrefixElement prefixElement = maybePrefix; | 789 PrefixElement prefixElement = maybePrefix; |
806 if (prefixElement.isDeferred) { | 790 if (prefixElement.isDeferred) { |
807 return prefixElement; | 791 return prefixElement; |
808 } | 792 } |
809 } | 793 } |
810 return null; | 794 return null; |
811 } | 795 } |
812 } | 796 } |
OLD | NEW |