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

Unified Diff: pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart

Issue 895813006: dart2js: store typeVariableReader stubs in the model. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comment. Created 5 years, 10 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
Index: pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart
diff --git a/pkg/compiler/lib/src/js_emitter/type_test_generator.dart b/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart
similarity index 84%
rename from pkg/compiler/lib/src/js_emitter/type_test_generator.dart
rename to pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart
index bb2b0b9a059a90ff08fdd48a364ea5eb0960b56e..9abed6de950677f102514280d17a001378558ea0 100644
--- a/pkg/compiler/lib/src/js_emitter/type_test_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart
@@ -20,12 +20,12 @@ class TypeTestProperties {
final Map<String, jsAst.Node> properties = <String, jsAst.Node>{};
}
-class TypeTestGenerator {
+class RuntimeTypeGenerator {
final Compiler compiler;
final CodeEmitterTask emitterTask;
final Namer namer;
- TypeTestGenerator(this.compiler, this.emitterTask, this.namer);
+ RuntimeTypeGenerator(this.compiler, this.emitterTask, this.namer);
JavaScriptBackend get backend => compiler.backend;
TypeTestRegistry get typeTestRegistry => emitterTask.typeTestRegistry;
@@ -264,4 +264,48 @@ class TypeTestGenerator {
generateSubstitution, alreadyGenerated);
}
}
+
+ List<StubMethod> generateTypeVariableReaderStubs(ClassElement classElement) {
+ List<StubMethod> stubs = <StubMethod>[];
+ List typeVariables = [];
+ ClassElement superclass = classElement;
+ while (superclass != null) {
+ for (TypeVariableType parameter in superclass.typeVariables) {
+ if (backend.emitter.readTypeVariables.contains(parameter.element)) {
+ stubs.add(
+ _generateTypeVariableReader(classElement, parameter.element));
+ }
+ }
+ superclass = superclass.superclass;
+ }
+
+ return stubs;
+ }
+
+ StubMethod _generateTypeVariableReader(ClassElement cls,
+ TypeVariableElement element) {
+ String name = namer.readTypeVariableName(element);
+ int index = RuntimeTypes.getTypeVariableIndex(element);
+ jsAst.Expression computeTypeVariable;
+
+ Substitution substitution =
+ backend.rti.computeSubstitution(
+ cls, element.typeDeclaration, alwaysGenerateFunction: true);
+ if (substitution != null) {
+ computeTypeVariable =
+ js(r'#.apply(null, this.$builtinTypeInfo)',
+ substitution.getCodeForVariable(index, backend.rti));
+ } else {
+ // TODO(ahe): These can be generated dynamically.
+ computeTypeVariable =
+ js(r'this.$builtinTypeInfo && this.$builtinTypeInfo[#]',
+ js.number(index));
+ }
+ jsAst.Expression convertRtiToRuntimeType = backend.emitter
+ .staticFunctionAccess(backend.findHelper('convertRtiToRuntimeType'));
+
+ return new StubMethod(name,
+ js('function () { return #(#) }',
+ [convertRtiToRuntimeType, computeTypeVariable]));
+ }
}
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/program_builder.dart ('k') | pkg/compiler/lib/src/js_emitter/type_test_generator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698