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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart

Issue 762213002: Support top-level field declaration and assignment in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // IrNodes are kept in a separate library to have precise control over their 5 // IrNodes are kept in a separate library to have precise control over their
6 // dependencies on other parts of the system. 6 // dependencies on other parts of the system.
7 library dart2js.ir_nodes; 7 library dart2js.ir_nodes;
8 8
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart' as values show ConstantValue; 10 import '../constants/values.dart' as values show ConstantValue;
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // This is basically a function definition with an empty parameter list and a 560 // This is basically a function definition with an empty parameter list and a
561 // field element instead of a function element and no const declarations, and 561 // field element instead of a function element and no const declarations, and
562 // never a getter or setter, though that's less important. 562 // never a getter or setter, though that's less important.
563 class FieldDefinition extends Node 563 class FieldDefinition extends Node
564 implements InteriorNode, ExecutableDefinition { 564 implements InteriorNode, ExecutableDefinition {
565 final FieldElement element; 565 final FieldElement element;
566 final Continuation returnContinuation; 566 final Continuation returnContinuation;
567 Expression body; 567 Expression body;
568 568
569 FieldDefinition(this.element, this.returnContinuation, this.body); 569 FieldDefinition(this.element, this.returnContinuation, this.body);
570
571 FieldDefinition.withoutInitializer(this.element)
572 : this.returnContinuation = null;
573
570 accept(Visitor visitor) => visitor.visitFieldDefinition(this); 574 accept(Visitor visitor) => visitor.visitFieldDefinition(this);
571 applyPass(Pass pass) => pass.rewriteFieldDefinition(this); 575 applyPass(Pass pass) => pass.rewriteFieldDefinition(this);
576
577 /// `true` if this field has no initializer.
578 ///
579 /// If `true` [body] and [returnContinuation] are `null`.
580 ///
581 /// This is different from a initializer that is `null`. Consider this class:
582 ///
583 /// class Class {
584 /// final field;
585 /// Class.a(this.field);
586 /// Class.b() : this.field = null;
587 /// Class.c();
588 /// }
589 ///
590 /// If `field` had an initializer, possibly `null`, constructors `Class.a` and
591 /// `Class.b` would be invalid, and since `field` has no initializer
592 /// constructor `Class.c` is invalid. We therefore need to distinguish the two
593 /// cases.
594 bool get hasInitializer => body != null;
572 } 595 }
573 596
574 /// A function definition, consisting of parameters and a body. The parameters 597 /// A function definition, consisting of parameters and a body. The parameters
575 /// include a distinguished continuation parameter. 598 /// include a distinguished continuation parameter.
576 class FunctionDefinition extends Node 599 class FunctionDefinition extends Node
577 implements InteriorNode, ExecutableDefinition { 600 implements InteriorNode, ExecutableDefinition {
578 final FunctionElement element; 601 final FunctionElement element;
579 final Continuation returnContinuation; 602 final Continuation returnContinuation;
580 final List<Parameter> parameters; 603 final List<Parameter> parameters;
581 Expression body; 604 Expression body;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 // while leaving other nodes for subclasses (i.e., visitLiteralList). 689 // while leaving other nodes for subclasses (i.e., visitLiteralList).
667 visitNode(Node node) { 690 visitNode(Node node) {
668 throw "RecursiveVisitor is stale, add missing visit overrides"; 691 throw "RecursiveVisitor is stale, add missing visit overrides";
669 } 692 }
670 693
671 processReference(Reference ref) {} 694 processReference(Reference ref) {}
672 695
673 processFieldDefinition(FieldDefinition node) {} 696 processFieldDefinition(FieldDefinition node) {}
674 visitFieldDefinition(FieldDefinition node) { 697 visitFieldDefinition(FieldDefinition node) {
675 processFieldDefinition(node); 698 processFieldDefinition(node);
676 visit(node.body); 699 if (node.hasInitializer) {
700 visit(node.body);
701 }
677 } 702 }
678 703
679 processFunctionDefinition(FunctionDefinition node) {} 704 processFunctionDefinition(FunctionDefinition node) {}
680 visitFunctionDefinition(FunctionDefinition node) { 705 visitFunctionDefinition(FunctionDefinition node) {
681 processFunctionDefinition(node); 706 processFunctionDefinition(node);
682 node.parameters.forEach(visitParameter); 707 node.parameters.forEach(visitParameter);
683 visit(node.body); 708 if (!node.isAbstract) {
709 visit(node.body);
710 }
684 } 711 }
685 712
686 // Expressions. 713 // Expressions.
687 714
688 processLetPrim(LetPrim node) {} 715 processLetPrim(LetPrim node) {}
689 visitLetPrim(LetPrim node) { 716 visitLetPrim(LetPrim node) {
690 processLetPrim(node); 717 processLetPrim(node);
691 visit(node.primitive); 718 visit(node.primitive);
692 visit(node.body); 719 visit(node.body);
693 } 720 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 if (primitive.registerIndex != null) { 913 if (primitive.registerIndex != null) {
887 getRegisterArray(primitive.hint).releaseIndex(primitive.registerIndex); 914 getRegisterArray(primitive.hint).releaseIndex(primitive.registerIndex);
888 } 915 }
889 } 916 }
890 917
891 void visitReference(Reference reference) { 918 void visitReference(Reference reference) {
892 allocate(reference.definition); 919 allocate(reference.definition);
893 } 920 }
894 921
895 void visitFieldDefinition(FieldDefinition node) { 922 void visitFieldDefinition(FieldDefinition node) {
896 visit(node.body); 923 if (node.hasInitializer) {
924 visit(node.body);
925 }
897 } 926 }
898 927
899 void visitFunctionDefinition(FunctionDefinition node) { 928 void visitFunctionDefinition(FunctionDefinition node) {
900 if (!node.isAbstract) { 929 if (!node.isAbstract) {
901 visit(node.body); 930 visit(node.body);
902 } 931 }
903 node.parameters.forEach(allocate); // Assign indices to unused parameters. 932 node.parameters.forEach(allocate); // Assign indices to unused parameters.
904 } 933 }
905 934
906 void visitLetPrim(LetPrim node) { 935 void visitLetPrim(LetPrim node) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 } 1033 }
1005 1034
1006 // JavaScript specific nodes. 1035 // JavaScript specific nodes.
1007 1036
1008 void visitIdentical(Identical node) { 1037 void visitIdentical(Identical node) {
1009 visitReference(node.left); 1038 visitReference(node.left);
1010 visitReference(node.right); 1039 visitReference(node.right);
1011 } 1040 }
1012 } 1041 }
1013 1042
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder_visitor.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698