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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/universe/universe.dart

Issue 12210142: Implement is-checks against type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add a comment. Created 7 years, 9 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 | Annotate | Revision Log
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 universe; 5 library universe;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../elements/elements.dart'; 8 import '../elements/elements.dart';
9 import '../dart2jslib.dart'; 9 import '../dart2jslib.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return hasMatchingSelector(invokedSetters[member.name], member, compiler); 81 return hasMatchingSelector(invokedSetters[member.name], member, compiler);
82 } 82 }
83 83
84 bool hasFieldGetter(Element member, Compiler compiler) { 84 bool hasFieldGetter(Element member, Compiler compiler) {
85 return fieldGetters.contains(member); 85 return fieldGetters.contains(member);
86 } 86 }
87 87
88 bool hasFieldSetter(Element member, Compiler compiler) { 88 bool hasFieldSetter(Element member, Compiler compiler) {
89 return fieldSetters.contains(member); 89 return fieldSetters.contains(member);
90 } 90 }
91
92 /**
93 * Compute type arguments of classes that use one of their type variables in
94 * is-checks and add the is-checks that they imply.
95 *
96 * This function must be called after all is-checks have been registered.
97 *
98 * TODO(karlklose): move these computations into a function producing an
99 * immutable datastructure.
100 */
101 void addImplicitChecks(Iterable<ClassElement> classesUsingChecks) {
102 // If there are no classes that use their variables in checks, there is
103 // nothing to do.
104 if (classesUsingChecks.isEmpty) return;
105 // Find all instantiated types that are a subtype of a class that uses
106 // one of its type arguments in an is-check and add the arguments to the
107 // set of is-checks.
108 // TODO(karlklose): replace this with code that uses a subtype lookup
109 // datastructure in the world.
110 for (DartType type in instantiatedTypes) {
111 if (type.kind != TypeKind.INTERFACE) continue;
112 InterfaceType classType = type;
113 for (ClassElement cls in classesUsingChecks) {
114 // We need the type as instance of its superclass anyway, so we just
115 // try to compute the substitution; if the result is [:null:], the
116 // classes are not related.
117 InterfaceType instance = classType.asInstanceOf(cls);
118 if (instance == null) continue;
119 Link<DartType> typeArguments = instance.typeArguments;
120 for (DartType argument in typeArguments) {
121 isChecks.add(argument);
122 }
123 }
124 }
125 }
91 } 126 }
92 127
93 class SelectorKind { 128 class SelectorKind {
94 final String name; 129 final String name;
95 const SelectorKind(this.name); 130 const SelectorKind(this.name);
96 131
97 static const SelectorKind GETTER = const SelectorKind('getter'); 132 static const SelectorKind GETTER = const SelectorKind('getter');
98 static const SelectorKind SETTER = const SelectorKind('setter'); 133 static const SelectorKind SETTER = const SelectorKind('setter');
99 static const SelectorKind CALL = const SelectorKind('call'); 134 static const SelectorKind CALL = const SelectorKind('call');
100 static const SelectorKind OPERATOR = const SelectorKind('operator'); 135 static const SelectorKind OPERATOR = const SelectorKind('operator');
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 if (cls.isSubclassOf(other)) { 566 if (cls.isSubclassOf(other)) {
532 // Resolve an invocation of [element.name] on [self]. If it 567 // Resolve an invocation of [element.name] on [self]. If it
533 // is found, this selector is a candidate. 568 // is found, this selector is a candidate.
534 return hasElementIn(self, element) && appliesUntyped(element, compiler); 569 return hasElementIn(self, element) && appliesUntyped(element, compiler);
535 } 570 }
536 } 571 }
537 572
538 return false; 573 return false;
539 } 574 }
540 } 575 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698