Chromium Code Reviews| 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 library elements; | 5 library elements; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart' show Resolution; | 8 import '../common/resolution.dart' show Resolution; |
| 9 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
| 10 import '../constants/constructors.dart'; | 10 import '../constants/constructors.dart'; |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 | 686 |
| 687 static bool isListSupertype(Element element, Compiler compiler) { | 687 static bool isListSupertype(Element element, Compiler compiler) { |
| 688 LibraryElement coreLibrary = compiler.coreLibrary; | 688 LibraryElement coreLibrary = compiler.coreLibrary; |
| 689 return element == coreLibrary.find('Iterable'); | 689 return element == coreLibrary.find('Iterable'); |
| 690 } | 690 } |
| 691 | 691 |
| 692 /// A `compareTo` function that places [Element]s in a consistent order based | 692 /// A `compareTo` function that places [Element]s in a consistent order based |
| 693 /// on the source code order. | 693 /// on the source code order. |
| 694 static int compareByPosition(Element a, Element b) { | 694 static int compareByPosition(Element a, Element b) { |
| 695 if (identical(a, b)) return 0; | 695 if (identical(a, b)) return 0; |
| 696 int r = a.library.compareTo(b.library); | 696 int r = _compareLibraries(a.library, b.library); |
| 697 if (r != 0) return r; | 697 if (r != 0) return r; |
| 698 r = a.compilationUnit.compareTo(b.compilationUnit); | 698 r = _compareCompilationUnits(a.compilationUnit, b.compilationUnit); |
| 699 if (r != 0) return r; | 699 if (r != 0) return r; |
| 700 int offsetA = a.sourceOffset ?? -1; | 700 int offsetA = a.sourceOffset ?? -1; |
| 701 int offsetB = b.sourceOffset ?? -1; | 701 int offsetB = b.sourceOffset ?? -1; |
| 702 r = offsetA.compareTo(offsetB); | 702 r = offsetA.compareTo(offsetB); |
| 703 if (r != 0) return r; | 703 if (r != 0) return r; |
| 704 r = a.name.compareTo(b.name); | 704 r = a.name.compareTo(b.name); |
| 705 if (r != 0) return r; | 705 if (r != 0) return r; |
| 706 // Same file, position and name. If this happens, we should find out why | 706 // Same file, position and name. If this happens, we should find out why |
| 707 // and make the order total and independent of hashCode. | 707 // and make the order total and independent of hashCode. |
| 708 return a.hashCode.compareTo(b.hashCode); | 708 return a.hashCode.compareTo(b.hashCode); |
| 709 } | 709 } |
| 710 | 710 |
| 711 // Somewhat stable ordering for [LibraryElement]s | |
| 712 static int _compareLibraries(LibraryElement a, LibraryElement b) { | |
| 713 if (a == b) return 0; | |
| 714 | |
| 715 int byCanonicalUriPath() { | |
| 716 return a.canonicalUri.path.compareTo(b.canonicalUri.path); | |
| 717 } | |
| 718 | |
| 719 // Order: platform < package < other. | |
| 720 if (a.isPlatformLibrary) { | |
| 721 if (b.isPlatformLibrary) return byCanonicalUriPath(); | |
| 722 return -1; | |
| 723 } | |
| 724 if (b.isPlatformLibrary) return 1; | |
| 725 | |
| 726 if (a.isPackageLibrary) { | |
| 727 if (b.isPackageLibrary) return byCanonicalUriPath(); | |
| 728 return -1; | |
| 729 } | |
| 730 if (b.isPackageLibrary) return 1; | |
| 731 | |
| 732 return _compareCanonicalUri(a.canonicalUri, b.canonicalUri); | |
| 733 } | |
| 734 | |
| 735 static int _compareCanonicalUri(Uri a, Uri b) { | |
| 736 int r = a.scheme.compareTo(b.scheme); | |
| 737 if (r != 0) return r; | |
| 738 | |
| 739 // We would like the order of 'file:' Uris to be stable across different | |
|
Siggi Cherem (dart-lang)
2016/08/09 22:11:21
Can we add an extra rule here that if scheme == fi
| |
| 740 // users or different builds from temporary directories. We sort by | |
| 741 // pathSegments elements from the last to the first since that tends to find | |
| 742 // a stable distinction regardless of directory root. | |
| 743 List<String> aSegments = a.pathSegments; | |
| 744 List<String> bSegments = b.pathSegments; | |
| 745 int aI = aSegments.length; | |
| 746 int bI = bSegments.length; | |
| 747 while (aI > 0 && bI > 0) { | |
| 748 String aSegment = aSegments[--aI]; | |
| 749 String bSegment = bSegments[--bI]; | |
| 750 r = aSegment.compareTo(bSegment); | |
| 751 if (r != 0) return r; | |
| 752 } | |
| 753 return aI.compareTo(bI); // Shortest first. | |
| 754 } | |
| 755 | |
| 756 static int _compareCompilationUnits(CompilationUnit a, CompilationUnit b) { | |
| 757 if (a == b) return 0; | |
| 758 // Compilation units are compared only within the same library so we expect | |
| 759 // the Uris to usually be clustered together with a common scheme and path | |
| 760 // prefix. | |
| 761 Uri aUri = a.script.readableUri; | |
| 762 Uri bUri = b.script.readableUri; | |
| 763 return '${aUri}'.compareTo('${bUri}'); | |
| 764 } | |
| 765 | |
| 711 static List<Element> sortedByPosition(Iterable<Element> elements) { | 766 static List<Element> sortedByPosition(Iterable<Element> elements) { |
| 712 return elements.toList()..sort(compareByPosition); | 767 return elements.toList()..sort(compareByPosition); |
| 713 } | 768 } |
| 714 | 769 |
| 715 static bool isFixedListConstructorCall( | 770 static bool isFixedListConstructorCall( |
| 716 Element element, Send node, Compiler compiler) { | 771 Element element, Send node, Compiler compiler) { |
| 717 return element == compiler.unnamedListConstructor && | 772 return element == compiler.unnamedListConstructor && |
| 718 node.isCall && | 773 node.isCall && |
| 719 !node.arguments.isEmpty && | 774 !node.arguments.isEmpty && |
| 720 node.arguments.tail.isEmpty; | 775 node.arguments.tail.isEmpty; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 925 String get libraryName; | 980 String get libraryName; |
| 926 | 981 |
| 927 /// Returns the library name (as defined by the library tag) or for script | 982 /// Returns the library name (as defined by the library tag) or for script |
| 928 /// (which have no library tag) the script file name. The latter case is used | 983 /// (which have no library tag) the script file name. The latter case is used |
| 929 /// to provide a 'library name' for scripts to use for instance in dartdoc. | 984 /// to provide a 'library name' for scripts to use for instance in dartdoc. |
| 930 /// | 985 /// |
| 931 /// Note: the returned filename is still escaped ("a%20b.dart" instead of | 986 /// Note: the returned filename is still escaped ("a%20b.dart" instead of |
| 932 /// "a b.dart"). | 987 /// "a b.dart"). |
| 933 String get libraryOrScriptName; | 988 String get libraryOrScriptName; |
| 934 | 989 |
| 935 int compareTo(LibraryElement other); | 990 //int compareTo(LibraryElement other); |
|
Siggi Cherem (dart-lang)
2016/08/09 22:11:21
delete?
| |
| 936 } | 991 } |
| 937 | 992 |
| 938 /// The implicit scope defined by a import declaration with a prefix clause. | 993 /// The implicit scope defined by a import declaration with a prefix clause. |
| 939 abstract class PrefixElement extends Element { | 994 abstract class PrefixElement extends Element { |
| 940 Element lookupLocalMember(String memberName); | 995 Element lookupLocalMember(String memberName); |
| 941 | 996 |
| 942 void forEachLocalMember(void f(Element member)); | 997 void forEachLocalMember(void f(Element member)); |
| 943 | 998 |
| 944 /// Is true if this prefix belongs to a deferred import. | 999 /// Is true if this prefix belongs to a deferred import. |
| 945 bool get isDeferred; | 1000 bool get isDeferred; |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1855 /// by a field. | 1910 /// by a field. |
| 1856 bool get isDeclaredByField; | 1911 bool get isDeclaredByField; |
| 1857 | 1912 |
| 1858 /// Returns `true` if this member is abstract. | 1913 /// Returns `true` if this member is abstract. |
| 1859 bool get isAbstract; | 1914 bool get isAbstract; |
| 1860 | 1915 |
| 1861 /// If abstract, [implementation] points to the overridden concrete member, | 1916 /// If abstract, [implementation] points to the overridden concrete member, |
| 1862 /// if any. Otherwise [implementation] points to the member itself. | 1917 /// if any. Otherwise [implementation] points to the member itself. |
| 1863 Member get implementation; | 1918 Member get implementation; |
| 1864 } | 1919 } |
| OLD | NEW |