Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: pkg/compiler/lib/src/elements/entity_utils.dart

Issue 2918543003: Handle static invocation (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/js_backend/namer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 library entity_utils;
6
7 import 'entities.dart';
8
9 // Somewhat stable ordering for libraries using [Uri]s
10 int compareLibrariesUris(Uri a, Uri b) {
11 if (a == b) return 0;
12
13 int byCanonicalUriPath() {
14 return a.path.compareTo(b.path);
15 }
16
17 // Order: platform < package < other.
18 if (a.scheme == 'dart') {
19 if (b.scheme == 'dart') return byCanonicalUriPath();
20 return -1;
21 }
22 if (b.scheme == 'dart') return 1;
23
24 if (a.scheme == 'package') {
25 if (b.scheme == 'package') return byCanonicalUriPath();
26 return -1;
27 }
28 if (b.scheme == 'package') return 1;
29
30 return _compareCanonicalUri(a, b);
31 }
32
33 int _compareCanonicalUri(Uri a, Uri b) {
34 int r = a.scheme.compareTo(b.scheme);
35 if (r != 0) return r;
36
37 // We would like the order of 'file:' Uris to be stable across different
38 // users or different builds from temporary directories. We sort by
39 // pathSegments elements from the last to the first since that tends to find
40 // a stable distinction regardless of directory root.
41 List<String> aSegments = a.pathSegments;
42 List<String> bSegments = b.pathSegments;
43 int aI = aSegments.length;
44 int bI = bSegments.length;
45 while (aI > 0 && bI > 0) {
46 String aSegment = aSegments[--aI];
47 String bSegment = bSegments[--bI];
48 r = aSegment.compareTo(bSegment);
49 if (r != 0) return r;
50 }
51 return aI.compareTo(bI); // Shortest first.
52 }
53
54 /// Compare URIs of compilation units.
55 int compareSourceUris(Uri uri1, Uri uri2) {
56 if (uri1 == uri2) return 0;
57 // Compilation units are compared only within the same library so we expect
58 // the Uris to usually be clustered together with a common scheme and path
59 // prefix.
60 return '${uri1}'.compareTo('${uri2}');
61 }
62
63 /// Compare entities within the same compilation unit.
64 int compareEntities(Entity element1, int line1, int column1, Entity element2,
65 int line2, int column2) {
66 line1 ??= -1;
67 line2 ??= -1;
68 int r = line1.compareTo(line2);
69 if (r != 0) return r;
70
71 column1 ??= -1;
72 column2 ??= -1;
73 r = column1.compareTo(column2);
74 if (r != 0) return r;
75
76 r = element1.name.compareTo(element2.name);
77 if (r != 0) return r;
78
79 // Same file, position and name. If this happens, we should find out why
80 // and make the order total and independent of hashCode.
81 return element1.hashCode.compareTo(element2.hashCode);
82 }
83
84 String reconstructConstructorName(FunctionEntity element) {
85 String className = element.enclosingClass.name;
86 if (element.name == '') {
87 return className;
88 } else {
89 return '$className\$${element.name}';
90 }
91 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/js_backend/namer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698