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

Side by Side Diff: pkg/compiler/lib/src/elements/elements.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/closure.dart ('k') | pkg/compiler/lib/src/elements/entity_utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 '../constants/constructors.dart'; 9 import '../constants/constructors.dart';
10 import '../constants/expressions.dart'; 10 import '../constants/expressions.dart';
11 import '../common_elements.dart' show CommonElements; 11 import '../common_elements.dart' show CommonElements;
12 import '../ordered_typeset.dart' show OrderedTypeSet; 12 import '../ordered_typeset.dart' show OrderedTypeSet;
13 import '../resolution/scope.dart' show Scope; 13 import '../resolution/scope.dart' show Scope;
14 import '../resolution/tree_elements.dart' show TreeElements; 14 import '../resolution/tree_elements.dart' show TreeElements;
15 import '../script.dart'; 15 import '../script.dart';
16 import 'package:front_end/src/fasta/scanner.dart' 16 import 'package:front_end/src/fasta/scanner.dart'
17 show Token, isUserDefinableOperator, isMinusOperator; 17 show Token, isUserDefinableOperator, isMinusOperator;
18 import '../tree/tree.dart' hide AsyncModifier; 18 import '../tree/tree.dart' hide AsyncModifier;
19 import '../universe/call_structure.dart'; 19 import '../universe/call_structure.dart';
20 import '../util/util.dart'; 20 import '../util/util.dart';
21 import '../world.dart' show ClosedWorld; 21 import '../world.dart' show ClosedWorld;
22 import 'entities.dart'; 22 import 'entities.dart';
23 import 'entity_utils.dart' as utils;
23 import 'names.dart'; 24 import 'names.dart';
24 import 'resolution_types.dart'; 25 import 'resolution_types.dart';
25 import 'types.dart'; 26 import 'types.dart';
26 import 'visitor.dart' show ElementVisitor; 27 import 'visitor.dart' show ElementVisitor;
27 28
28 const int STATE_NOT_STARTED = 0; 29 const int STATE_NOT_STARTED = 0;
29 const int STATE_STARTED = 1; 30 const int STATE_STARTED = 1;
30 const int STATE_DONE = 2; 31 const int STATE_DONE = 2;
31 32
32 class ElementCategory { 33 class ElementCategory {
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 if (element == null && selector.asIdentifier() == null) return true; 536 if (element == null && selector.asIdentifier() == null) return true;
536 if (element == null) return false; 537 if (element == null) return false;
537 // foo() with foo a local or a parameter. 538 // foo() with foo a local or a parameter.
538 return isLocal(element); 539 return isLocal(element);
539 } 540 }
540 541
541 static String reconstructConstructorNameSourceString(FunctionEntity element) { 542 static String reconstructConstructorNameSourceString(FunctionEntity element) {
542 if (element.name == '') { 543 if (element.name == '') {
543 return element.enclosingClass.name; 544 return element.enclosingClass.name;
544 } else { 545 } else {
545 return reconstructConstructorName(element); 546 return utils.reconstructConstructorName(element);
546 } 547 }
547 } 548 }
548 549
549 // TODO(johnniwinther): Move this (other similar) to an entity_utils library.
550 static String reconstructConstructorName(FunctionEntity element) {
551 String className = element.enclosingClass.name;
552 if (element.name == '') {
553 return className;
554 } else {
555 return '$className\$${element.name}';
556 }
557 }
558
559 static String constructorNameForDiagnostics( 550 static String constructorNameForDiagnostics(
560 String className, String constructorName) { 551 String className, String constructorName) {
561 String classNameString = className; 552 String classNameString = className;
562 String constructorNameString = constructorName; 553 String constructorNameString = constructorName;
563 return (constructorName == '') 554 return (constructorName == '')
564 ? classNameString 555 ? classNameString
565 : "$classNameString.$constructorNameString"; 556 : "$classNameString.$constructorNameString";
566 } 557 }
567 558
568 /// Returns `true` if [name] is the name of an operator method. 559 /// Returns `true` if [name] is the name of an operator method.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 if (identical(op, '|=')) return '|'; 651 if (identical(op, '|=')) return '|';
661 if (identical(op, '??=')) return '??'; 652 if (identical(op, '??=')) return '??';
662 653
663 return null; 654 return null;
664 } 655 }
665 656
666 /// A `compareTo` function that places [Element]s in a consistent order based 657 /// A `compareTo` function that places [Element]s in a consistent order based
667 /// on the source code order. 658 /// on the source code order.
668 static int compareByPosition(Element a, Element b) { 659 static int compareByPosition(Element a, Element b) {
669 if (identical(a, b)) return 0; 660 if (identical(a, b)) return 0;
670 int r = _compareLibraries(a.library, b.library); 661 int r = utils.compareLibrariesUris(
662 a.library.canonicalUri, b.library.canonicalUri);
671 if (r != 0) return r; 663 if (r != 0) return r;
672 r = _compareCompilationUnits(a.compilationUnit, b.compilationUnit); 664 r = utils.compareSourceUris(a.compilationUnit.script.readableUri,
665 b.compilationUnit.script.readableUri);
673 if (r != 0) return r; 666 if (r != 0) return r;
674 int offsetA = a.sourceOffset ?? -1; 667 return utils.compareEntities(a, a.sourceOffset, -1, b, b.sourceOffset, -1);
675 int offsetB = b.sourceOffset ?? -1;
676 r = offsetA.compareTo(offsetB);
677 if (r != 0) return r;
678 r = a.name.compareTo(b.name);
679 if (r != 0) return r;
680 // Same file, position and name. If this happens, we should find out why
681 // and make the order total and independent of hashCode.
682 return a.hashCode.compareTo(b.hashCode);
683 }
684
685 // Somewhat stable ordering for [LibraryElement]s
686 static int _compareLibraries(LibraryElement a, LibraryElement b) {
687 if (a == b) return 0;
688
689 int byCanonicalUriPath() {
690 return a.canonicalUri.path.compareTo(b.canonicalUri.path);
691 }
692
693 // Order: platform < package < other.
694 if (a.isPlatformLibrary) {
695 if (b.isPlatformLibrary) return byCanonicalUriPath();
696 return -1;
697 }
698 if (b.isPlatformLibrary) return 1;
699
700 if (a.isPackageLibrary) {
701 if (b.isPackageLibrary) return byCanonicalUriPath();
702 return -1;
703 }
704 if (b.isPackageLibrary) return 1;
705
706 return _compareCanonicalUri(a.canonicalUri, b.canonicalUri);
707 }
708
709 static int _compareCanonicalUri(Uri a, Uri b) {
710 int r = a.scheme.compareTo(b.scheme);
711 if (r != 0) return r;
712
713 // We would like the order of 'file:' Uris to be stable across different
714 // users or different builds from temporary directories. We sort by
715 // pathSegments elements from the last to the first since that tends to find
716 // a stable distinction regardless of directory root.
717 List<String> aSegments = a.pathSegments;
718 List<String> bSegments = b.pathSegments;
719 int aI = aSegments.length;
720 int bI = bSegments.length;
721 while (aI > 0 && bI > 0) {
722 String aSegment = aSegments[--aI];
723 String bSegment = bSegments[--bI];
724 r = aSegment.compareTo(bSegment);
725 if (r != 0) return r;
726 }
727 return aI.compareTo(bI); // Shortest first.
728 }
729
730 static int _compareCompilationUnits(
731 CompilationUnitElement a, CompilationUnitElement b) {
732 if (a == b) return 0;
733 // Compilation units are compared only within the same library so we expect
734 // the Uris to usually be clustered together with a common scheme and path
735 // prefix.
736 Uri aUri = a.script.readableUri;
737 Uri bUri = b.script.readableUri;
738 return '${aUri}'.compareTo('${bUri}');
739 } 668 }
740 669
741 static List<E> sortedByPosition<E extends Element>(Iterable<E> elements) { 670 static List<E> sortedByPosition<E extends Element>(Iterable<E> elements) {
742 return elements.toList()..sort(compareByPosition); 671 return elements.toList()..sort(compareByPosition);
743 } 672 }
744 673
745 static bool isFixedListConstructorCall( 674 static bool isFixedListConstructorCall(
746 ConstructorEntity element, Send node, CommonElements commonElements) { 675 ConstructorEntity element, Send node, CommonElements commonElements) {
747 return commonElements.isUnnamedListConstructor(element) && 676 return commonElements.isUnnamedListConstructor(element) &&
748 node.isCall && 677 node.isCall &&
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 /// by a field. 1906 /// by a field.
1978 bool get isDeclaredByField; 1907 bool get isDeclaredByField;
1979 1908
1980 /// Returns `true` if this member is abstract. 1909 /// Returns `true` if this member is abstract.
1981 bool get isAbstract; 1910 bool get isAbstract;
1982 1911
1983 /// If abstract, [implementation] points to the overridden concrete member, 1912 /// If abstract, [implementation] points to the overridden concrete member,
1984 /// if any. Otherwise [implementation] points to the member itself. 1913 /// if any. Otherwise [implementation] points to the member itself.
1985 Member get implementation; 1914 Member get implementation;
1986 } 1915 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | pkg/compiler/lib/src/elements/entity_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698