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

Unified Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1011403003: cps-ir: Set runtime type information for new objects that require it. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/js_backend/codegen/codegen.dart
diff --git a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
index f6c7e21608b46c268c89575c9d7531f6141c63e8..f7447c328023299b86438afb9289d2e99e43d0a1 100644
--- a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
+++ b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
@@ -206,9 +206,10 @@ class CodeGenerator extends tree_ir.Visitor<dynamic, js.Expression> {
@override
js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) {
checkStaticTargetIsValid(node, node.target);
-
if (node.constant != null) return giveup(node);
- registry.registerInstantiatedClass(node.target.enclosingClass);
+
+ ClassElement instantiatedClass = node.target.enclosingClass;
+ registry.registerInstantiatedClass(instantiatedClass);
Selector selector = node.selector;
FunctionElement target = node.target;
List<js.Expression> arguments = visitArguments(node.arguments);
@@ -500,9 +501,24 @@ class CodeGenerator extends tree_ir.Visitor<dynamic, js.Expression> {
@override
js.Expression visitCreateInstance(tree_ir.CreateInstance node) {
- registry.registerInstantiatedClass(node.classElement);
- return new js.New(glue.constructorAccess(node.classElement),
- node.arguments.map(visitExpression).toList());
+ ClassElement cls = node.classElement;
+ registry.registerInstantiatedClass(cls);
+ js.Expression instance = new js.New(
+ glue.constructorAccess(cls),
+ node.arguments.map(visitExpression).toList());
+
+ List<tree_ir.Expression> typeInformation = node.typeInformation;
+ assert(typeInformation.isEmpty ||
+ typeInformation.length == cls.typeVariables.length);
+ if (typeInformation.isNotEmpty) {
+ FunctionElement helper = glue.getAddRuntimeTypeInformation();
+ js.Expression typeArguments = new js.ArrayInitializer(
+ typeInformation.map(visitExpression).toList());
+ return buildStaticHelperInvocation(helper,
+ <js.Expression>[instance, typeArguments]);
+ } else {
+ return instance;
+ }
}
@override
@@ -555,6 +571,12 @@ class CodeGenerator extends tree_ir.Visitor<dynamic, js.Expression> {
}
}
+ @override
+ js.Expression visitTypeExpression(tree_ir.TypeExpression node) {
+ List<js.Expression> arguments =
+ node.arguments.map(visitExpression).toList(growable: false);
+ return glue.generateTypeRepresentation(node.dartType, arguments);
+ }
// Dart-specific IR nodes
« no previous file with comments | « pkg/compiler/lib/src/dart_backend/backend_ast_emitter.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698