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

Unified Diff: lib/compiler/implementation/js_backend/emitter.dart

Issue 10951026: Fix algorithm to know whether we should emit an is check on a class: all interfaces/implemented cla… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/is_interfaces2_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/js_backend/emitter.dart
===================================================================
--- lib/compiler/implementation/js_backend/emitter.dart (revision 12536)
+++ lib/compiler/implementation/js_backend/emitter.dart (working copy)
@@ -637,7 +637,7 @@
}
});
- generateTypeTests(classElement, (Element other) {
+ generateIsTestsOn(classElement, (Element other) {
String code;
if (nativeEmitter.requiresNativeIsCheck(other)) {
code = 'function() { return true; }';
@@ -696,35 +696,48 @@
buffer.add('\n};\n\n');
}
- void generateTypeTests(ClassElement cls,
- void generateTypeTest(ClassElement element)) {
+ /**
+ * Generate "is tests" for [cls]: itself, and the "is tests" for the
+ * classes it implements. We don't need to add the "is tests" of the
+ * super class because they will be inherited at runtime.
+ */
+ void generateIsTestsOn(ClassElement cls,
+ void emitIsTest(ClassElement element)) {
if (checkedClasses.contains(cls)) {
- generateTypeTest(cls);
+ emitIsTest(cls);
}
- generateInterfacesIsTests(cls, generateTypeTest, new Set<Element>());
+ Set<Element> generated = new Set<Element>();
+ for (DartType interfaceType in cls.interfaces) {
+ generateInterfacesIsTests(interfaceType.element, emitIsTest, generated);
+ }
}
+ /**
+ * Generate "is tests" where [cls] is being implemented.
+ */
void generateInterfacesIsTests(ClassElement cls,
- void generateTypeTest(ClassElement element),
+ void emitIsTest(ClassElement element),
Set<Element> alreadyGenerated) {
+ void tryEmitTest(ClassElement cls) {
+ if (!alreadyGenerated.contains(cls) && checkedClasses.contains(cls)) {
+ alreadyGenerated.add(cls);
+ emitIsTest(cls);
+ }
+ };
+
+ tryEmitTest(cls);
+
for (DartType interfaceType in cls.interfaces) {
Element element = interfaceType.element;
- if (!alreadyGenerated.contains(element) &&
- checkedClasses.contains(element)) {
- alreadyGenerated.add(element);
- generateTypeTest(element);
- }
- generateInterfacesIsTests(element, generateTypeTest, alreadyGenerated);
+ tryEmitTest(element);
+ generateInterfacesIsTests(element, emitIsTest, alreadyGenerated);
+ }
- // Since [element] is implemented by [cls], we need to also emit
- // is checks for the superclass and its supertypes.
- ClassElement superclass = element.superclass;
- if (!alreadyGenerated.contains(superclass) &&
- checkedClasses.contains(superclass)) {
- alreadyGenerated.add(superclass);
- generateTypeTest(superclass);
- }
- generateInterfacesIsTests(superclass, generateTypeTest, alreadyGenerated);
+ // We need to also emit "is checks" for the superclass and its supertypes.
+ ClassElement superclass = cls.superclass;
+ if (superclass != null) {
+ tryEmitTest(superclass);
+ generateInterfacesIsTests(superclass, emitIsTest, alreadyGenerated);
}
}
« no previous file with comments | « no previous file | tests/language/is_interfaces2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698