Chromium Code Reviews| Index: pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart |
| diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart |
| index a4e07f70df2b7c2d65e0358a029f02943df6c773..6c8100ae44ae0513e2cd1949567d19abbdb29448 100644 |
| --- a/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart |
| +++ b/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart |
| @@ -567,8 +567,31 @@ class FieldDefinition extends Node |
| Expression body; |
| FieldDefinition(this.element, this.returnContinuation, this.body); |
| + |
| + FieldDefinition.withoutInitializer(this.element) |
| + : this.returnContinuation = null; |
| + |
| accept(Visitor visitor) => visitor.visitFieldDefinition(this); |
| applyPass(Pass pass) => pass.rewriteFieldDefinition(this); |
| + |
| + /// `true` if this field has no initializer. |
| + /// |
| + /// If `true` [body] and [returnContinuation] are `null`. |
| + /// |
| + /// This is different from a initializer that is `null`. Consider this class: |
| + /// |
| + /// class Class { |
|
sigurdm
2014/12/01 09:06:00
We should even create these as test cases
Johnni Winther
2014/12/01 13:00:39
Acknowledged.
|
| + /// final field; |
| + /// Class.a(this.field); |
| + /// Class.b() : this.field = null; |
| + /// Class.c(); |
| + /// } |
| + /// |
| + /// If `field` had an initializer, possibly `null`, constructors `Class.a` and |
| + /// `Class.b` would be invalid, and since `field` has no initializer |
| + /// constructor `Class.c` is invalid. We therefore need to distinguish the two |
| + /// cases. |
| + bool get hasInitializer => body != null; |
| } |
| /// A function definition, consisting of parameters and a body. The parameters |
| @@ -673,14 +696,18 @@ abstract class RecursiveVisitor extends Visitor { |
| processFieldDefinition(FieldDefinition node) {} |
| visitFieldDefinition(FieldDefinition node) { |
| processFieldDefinition(node); |
| - visit(node.body); |
| + if (node.hasInitializer) { |
| + visit(node.body); |
| + } |
| } |
| processFunctionDefinition(FunctionDefinition node) {} |
| visitFunctionDefinition(FunctionDefinition node) { |
| processFunctionDefinition(node); |
| node.parameters.forEach(visitParameter); |
| - visit(node.body); |
| + if (!node.isAbstract) { |
| + visit(node.body); |
| + } |
| } |
| // Expressions. |
| @@ -893,7 +920,9 @@ class RegisterAllocator extends Visitor { |
| } |
| void visitFieldDefinition(FieldDefinition node) { |
| - visit(node.body); |
| + if (node.hasInitializer) { |
| + visit(node.body); |
| + } |
| } |
| void visitFunctionDefinition(FunctionDefinition node) { |