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

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

Issue 2569733002: Even less reliance on Compiler.closedWorld (Closed)
Patch Set: Updated cf. comments. Created 4 years 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
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 '../compiler.dart' show Compiler; 9 import '../compiler.dart' show Compiler;
10 import '../constants/constructors.dart'; 10 import '../constants/constructors.dart';
11 import '../constants/expressions.dart'; 11 import '../constants/expressions.dart';
12 import '../core_types.dart' show CoreClasses; 12 import '../core_types.dart' show CoreClasses, CommonElements;
13 import '../dart_types.dart'; 13 import '../dart_types.dart';
14 import '../ordered_typeset.dart' show OrderedTypeSet; 14 import '../ordered_typeset.dart' show OrderedTypeSet;
15 import '../resolution/scope.dart' show Scope; 15 import '../resolution/scope.dart' show Scope;
16 import '../resolution/tree_elements.dart' show TreeElements; 16 import '../resolution/tree_elements.dart' show TreeElements;
17 import '../script.dart'; 17 import '../script.dart';
18 import '../tokens/token.dart' 18 import '../tokens/token.dart'
19 show Token, isUserDefinableOperator, isMinusOperator; 19 show Token, isUserDefinableOperator, isMinusOperator;
20 import '../tree/tree.dart'; 20 import '../tree/tree.dart';
21 import '../util/characters.dart' show $_; 21 import '../util/characters.dart' show $_;
22 import '../util/util.dart'; 22 import '../util/util.dart';
23 import '../world.dart' show ClosedWorld;
23 import 'entities.dart'; 24 import 'entities.dart';
24 import 'visitor.dart' show ElementVisitor; 25 import 'visitor.dart' show ElementVisitor;
25 26
26 part 'names.dart'; 27 part 'names.dart';
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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 if (identical(op, '<<=')) return '<<'; 669 if (identical(op, '<<=')) return '<<';
669 if (identical(op, '>>=')) return '>>'; 670 if (identical(op, '>>=')) return '>>';
670 if (identical(op, '&=')) return '&'; 671 if (identical(op, '&=')) return '&';
671 if (identical(op, '^=')) return '^'; 672 if (identical(op, '^=')) return '^';
672 if (identical(op, '|=')) return '|'; 673 if (identical(op, '|=')) return '|';
673 if (identical(op, '??=')) return '??'; 674 if (identical(op, '??=')) return '??';
674 675
675 return null; 676 return null;
676 } 677 }
677 678
678 static bool isNumberOrStringSupertype(Element element, Compiler compiler) { 679 static bool isNumberOrStringSupertype(
679 LibraryElement coreLibrary = compiler.commonElements.coreLibrary; 680 Element element, CommonElements commonElements) {
681 LibraryElement coreLibrary = commonElements.coreLibrary;
680 return (element == coreLibrary.find('Comparable')); 682 return (element == coreLibrary.find('Comparable'));
681 } 683 }
682 684
683 static bool isStringOnlySupertype(Element element, Compiler compiler) { 685 static bool isStringOnlySupertype(
684 LibraryElement coreLibrary = compiler.commonElements.coreLibrary; 686 Element element, CommonElements commonElements) {
687 LibraryElement coreLibrary = commonElements.coreLibrary;
685 return element == coreLibrary.find('Pattern'); 688 return element == coreLibrary.find('Pattern');
686 } 689 }
687 690
688 static bool isListSupertype(Element element, Compiler compiler) { 691 static bool isListSupertype(Element element, CommonElements commonElements) {
689 LibraryElement coreLibrary = compiler.commonElements.coreLibrary; 692 LibraryElement coreLibrary = commonElements.coreLibrary;
690 return element == coreLibrary.find('Iterable'); 693 return element == coreLibrary.find('Iterable');
691 } 694 }
692 695
693 /// A `compareTo` function that places [Element]s in a consistent order based 696 /// A `compareTo` function that places [Element]s in a consistent order based
694 /// on the source code order. 697 /// on the source code order.
695 static int compareByPosition(Element a, Element b) { 698 static int compareByPosition(Element a, Element b) {
696 if (identical(a, b)) return 0; 699 if (identical(a, b)) return 0;
697 int r = _compareLibraries(a.library, b.library); 700 int r = _compareLibraries(a.library, b.library);
698 if (r != 0) return r; 701 if (r != 0) return r;
699 r = _compareCompilationUnits(a.compilationUnit, b.compilationUnit); 702 r = _compareCompilationUnits(a.compilationUnit, b.compilationUnit);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 Uri aUri = a.script.readableUri; 766 Uri aUri = a.script.readableUri;
764 Uri bUri = b.script.readableUri; 767 Uri bUri = b.script.readableUri;
765 return '${aUri}'.compareTo('${bUri}'); 768 return '${aUri}'.compareTo('${bUri}');
766 } 769 }
767 770
768 static List<Element> sortedByPosition(Iterable<Element> elements) { 771 static List<Element> sortedByPosition(Iterable<Element> elements) {
769 return elements.toList()..sort(compareByPosition); 772 return elements.toList()..sort(compareByPosition);
770 } 773 }
771 774
772 static bool isFixedListConstructorCall( 775 static bool isFixedListConstructorCall(
773 Element element, Send node, Compiler compiler) { 776 Element element, Send node, CommonElements commonElements) {
774 return element == compiler.unnamedListConstructor && 777 return element == commonElements.unnamedListConstructor &&
775 node.isCall && 778 node.isCall &&
776 !node.arguments.isEmpty && 779 !node.arguments.isEmpty &&
777 node.arguments.tail.isEmpty; 780 node.arguments.tail.isEmpty;
778 } 781 }
779 782
780 static bool isGrowableListConstructorCall( 783 static bool isGrowableListConstructorCall(
781 Element element, Send node, Compiler compiler) { 784 Element element, Send node, CommonElements commonElements) {
782 return element == compiler.unnamedListConstructor && 785 return element == commonElements.unnamedListConstructor &&
783 node.isCall && 786 node.isCall &&
784 node.arguments.isEmpty; 787 node.arguments.isEmpty;
785 } 788 }
786 789
787 static bool isFilledListConstructorCall( 790 static bool isFilledListConstructorCall(
788 Element element, Send node, Compiler compiler) { 791 Element element, Send node, CommonElements commonElements) {
789 return element == compiler.filledListConstructor && 792 return element == commonElements.filledListConstructor &&
790 node.isCall && 793 node.isCall &&
791 !node.arguments.isEmpty && 794 !node.arguments.isEmpty &&
792 !node.arguments.tail.isEmpty && 795 !node.arguments.tail.isEmpty &&
793 node.arguments.tail.tail.isEmpty; 796 node.arguments.tail.tail.isEmpty;
794 } 797 }
795 798
796 static bool isConstructorOfTypedArraySubclass( 799 static bool isConstructorOfTypedArraySubclass(
797 Element element, Compiler compiler) { 800 Element element, ClosedWorld closedWorld) {
798 if (compiler.commonElements.typedDataLibrary == null) return false; 801 if (closedWorld.commonElements.typedDataLibrary == null) return false;
799 if (!element.isConstructor) return false; 802 if (!element.isConstructor) return false;
800 ConstructorElement constructor = element.implementation; 803 ConstructorElement constructor = element.implementation;
801 constructor = constructor.effectiveTarget; 804 constructor = constructor.effectiveTarget;
802 ClassElement cls = constructor.enclosingClass; 805 ClassElement cls = constructor.enclosingClass;
803 return cls.library == compiler.commonElements.typedDataLibrary && 806 return cls.library == closedWorld.commonElements.typedDataLibrary &&
804 compiler.backend.isNative(cls) && 807 closedWorld.backendClasses.isNative(cls) &&
805 compiler.closedWorld 808 closedWorld.isSubtypeOf(
806 .isSubtypeOf(cls, compiler.commonElements.typedDataClass) && 809 cls, closedWorld.commonElements.typedDataClass) &&
807 compiler.closedWorld.isSubtypeOf(cls, compiler.coreClasses.listClass) && 810 closedWorld.isSubtypeOf(cls, closedWorld.coreClasses.listClass) &&
808 constructor.name == ''; 811 constructor.name == '';
809 } 812 }
810 813
811 static bool switchStatementHasContinue( 814 static bool switchStatementHasContinue(
812 SwitchStatement node, TreeElements elements) { 815 SwitchStatement node, TreeElements elements) {
813 for (SwitchCase switchCase in node.cases) { 816 for (SwitchCase switchCase in node.cases) {
814 for (Node labelOrCase in switchCase.labelsAndCases) { 817 for (Node labelOrCase in switchCase.labelsAndCases) {
815 Node label = labelOrCase.asLabel(); 818 Node label = labelOrCase.asLabel();
816 if (label != null) { 819 if (label != null) {
817 LabelDefinition labelElement = elements.getLabelDefinition(label); 820 LabelDefinition labelElement = elements.getLabelDefinition(label);
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 /// by a field. 1934 /// by a field.
1932 bool get isDeclaredByField; 1935 bool get isDeclaredByField;
1933 1936
1934 /// Returns `true` if this member is abstract. 1937 /// Returns `true` if this member is abstract.
1935 bool get isAbstract; 1938 bool get isAbstract;
1936 1939
1937 /// If abstract, [implementation] points to the overridden concrete member, 1940 /// If abstract, [implementation] points to the overridden concrete member,
1938 /// if any. Otherwise [implementation] points to the member itself. 1941 /// if any. Otherwise [implementation] points to the member itself.
1939 Member get implementation; 1942 Member get implementation;
1940 } 1943 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/dump_info.dart ('k') | pkg/compiler/lib/src/inferrer/inferrer_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698