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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1160833003: Add support for null-aware operators to the CPS-IR. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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 | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/resolution/operators.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
index 6b78f6fffcf8e96d6d51e3e1766e41951f0ef459..debf805efb4f10b7631fb2c8039f082e5a285c1a 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
@@ -725,6 +725,18 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
}
@override
+ ir.Primitive visitIfNotNullDynamicPropertyGet(
+ ast.Send node,
+ ast.Node receiver,
+ Selector selector,
+ _) {
+ ir.Primitive target = visit(receiver);
+ return irBuilder.buildIfNotNullSend(
+ target,
+ nested(() => irBuilder.buildDynamicGet(target, selector)));
+ }
+
+ @override
ir.Primitive visitDynamicTypeLiteralGet(
ast.Send node,
ConstantExpression constant,
@@ -846,7 +858,7 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
@override
ir.Primitive visitIfNull(
ast.Send node, ast.Node left, ast.Node right, _) {
- internalError(node, "If-null not yet implemented in cps_ir");
+ return irBuilder.buildIfNull(build(left), subbuild(right));
}
@override
@@ -1065,6 +1077,21 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
translateDynamicArguments(arguments, selector.callStructure));
}
+ @override
+ ir.Primitive visitIfNotNullDynamicPropertyInvoke(
+ ast.Send node,
+ ast.Node receiver,
+ ast.NodeList arguments,
+ Selector selector,
+ _) {
+ ir.Primitive target = visit(receiver);
+ return irBuilder.buildIfNotNullSend(
+ target,
+ nested(() => irBuilder.buildDynamicInvocation(
+ target, selector,
+ translateDynamicArguments(arguments, selector.callStructure))));
+ }
+
ir.Primitive handleLocalInvoke(
ast.Send node,
LocalElement element,
@@ -1255,8 +1282,19 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
CompoundRhs rhs,
void setValue(ir.Primitive value)}) {
ir.Primitive value = getValue();
+ op.BinaryOperator operator = rhs.operator;
+ if (operator.kind == op.BinaryOperatorKind.IF_NULL) {
+ // Unlike other compound operators if-null conditionally will not do the
+ // assignment operation.
+ return irBuilder.buildIfNull(value, nested(() {
+ ir.Primitive newValue = build(rhs.rhs);
+ setValue(newValue);
+ return newValue;
+ }));
+ }
+
Selector operatorSelector =
- new Selector.binaryOperator(rhs.operator.selectorName);
+ new Selector.binaryOperator(operator.selectorName);
ir.Primitive rhsValue;
if (rhs.kind == CompoundKind.ASSIGNMENT) {
rhsValue = visit(rhs.rhs);
@@ -1286,6 +1324,19 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
}
@override
+ ir.Primitive visitIfNotNullDynamicPropertySet(
+ ast.SendSet node,
+ ast.Node receiver,
+ Selector selector,
+ ast.Node rhs,
+ _) {
+ ir.Primitive target = visit(receiver);
+ return irBuilder.buildIfNotNullSend(
+ target,
+ nested(() => irBuilder.buildDynamicSet(target, selector, visit(rhs))));
+ }
+
+ @override
ir.Primitive handleLocalSet(
ast.SendSet node,
LocalElement element,
@@ -1361,12 +1412,17 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
Selector setterSelector,
arg) {
ir.Primitive target = translateReceiver(receiver);
- return translateCompounds(
- getValue: () => irBuilder.buildDynamicGet(target, getterSelector),
- rhs: rhs,
- setValue: (ir.Primitive result) {
- irBuilder.buildDynamicSet(target, setterSelector, result);
- });
+ ir.Primitive helper() {
+ return translateCompounds(
+ getValue: () => irBuilder.buildDynamicGet(target, getterSelector),
+ rhs: rhs,
+ setValue: (ir.Primitive result) {
+ irBuilder.buildDynamicSet(target, setterSelector, result);
+ });
+ }
+ return node.isConditional
+ ? irBuilder.buildIfNotNullSend(target, nested(helper))
+ : helper();
}
ir.Primitive buildLocalNoSuchSetter(Local local, ir.Primitive value) {
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/resolution/operators.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698