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

Side by Side Diff: pkg/compiler/lib/src/kernel/kernel_visitor.dart

Issue 2682553002: Fix lingering switch statement test failures. (Closed)
Patch Set: . Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 import 'package:kernel/frontend/accessors.dart' 6 import 'package:kernel/frontend/accessors.dart'
7 show 7 show
8 Accessor, 8 Accessor,
9 IndexAccessor, 9 IndexAccessor,
10 NullAwarePropertyAccessor, 10 NullAwarePropertyAccessor,
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 buildStatement(statement, statements); 584 buildStatement(statement, statements);
585 } 585 }
586 } else { 586 } else {
587 if (buildStatement(node, statements)) forceBlock = true; 587 if (buildStatement(node, statements)) forceBlock = true;
588 if (!forceBlock && statements.length == 1) { 588 if (!forceBlock && statements.length == 1) {
589 return statements.single; 589 return statements.single;
590 } 590 }
591 // One VariableDefinitions statement node (dart2js AST) may generate 591 // One VariableDefinitions statement node (dart2js AST) may generate
592 // multiple statements in Kernel IR so we sometimes fall through here. 592 // multiple statements in Kernel IR so we sometimes fall through here.
593 } 593 }
594 return new ir.Block(statements); 594 return associateNode(new ir.Block(statements), node);
595 } 595 }
596 596
597 @override 597 @override
598 ir.Statement visitBreakStatement(BreakStatement node) { 598 ir.Statement visitBreakStatement(BreakStatement node) {
599 JumpTarget target = elements.getTargetOf(node); 599 JumpTarget target = elements.getTargetOf(node);
600 if (target == null || !target.statement.isValidBreakTarget()) { 600 if (target == null || !target.statement.isValidBreakTarget()) {
601 // This is a break in an invalid position. 601 // This is a break in an invalid position.
602 return new ir.InvalidStatement(); 602 return new ir.InvalidStatement();
603 } 603 }
604 // A break can break to itself in the degenerate case `label: break 604 // A break can break to itself in the degenerate case `label: break
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 } 819 }
820 820
821 @override 821 @override
822 ir.Statement visitLabeledStatement(LabeledStatement node) { 822 ir.Statement visitLabeledStatement(LabeledStatement node) {
823 Statement statement = node.statement; 823 Statement statement = node.statement;
824 ir.Statement result = (statement is Block) 824 ir.Statement result = (statement is Block)
825 // If [statement] is a Block, we need to ensure that we don't bypass 825 // If [statement] is a Block, we need to ensure that we don't bypass
826 // its visit method (so it can build break targets correctly). 826 // its visit method (so it can build break targets correctly).
827 ? statement.accept(this) 827 ? statement.accept(this)
828 : buildStatementInBlock(statement); 828 : buildStatementInBlock(statement);
829 associateNode(result, statement);
829 830
830 // A [LabeledStatement] isn't the actual jump target, instead, [statement] 831 // A [LabeledStatement] isn't the actual jump target, instead, [statement]
831 // is the target. This allows uniform handling of break and continue in 832 // is the target. This allows uniform handling of break and continue in
832 // loops. The following code simply assert that [result] has been generated 833 // loops. The following code simply assert that [result] has been generated
833 // correctly with respect to jump targets. 834 // correctly with respect to jump targets.
834 JumpTarget jumpTarget = elements.getTargetDefinition(node.statement); 835 JumpTarget jumpTarget = elements.getTargetDefinition(node.statement);
835 if (jumpTarget != null) { 836 if (jumpTarget != null) {
836 if (jumpTarget.isBreakTarget) { 837 if (jumpTarget.isBreakTarget) {
837 ir.LabeledStatement target = breakTargets[jumpTarget]; 838 ir.LabeledStatement target = breakTargets[jumpTarget];
838 if (target != null && target != result && target.parent == null) { 839 if (target != null && target != result && target.parent == null) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 expressions.add(visitForValue(match.expression)); 993 expressions.add(visitForValue(match.expression));
993 } else { 994 } else {
994 // Assert that labelOrCase is one of two known types: [CaseMatch] or 995 // Assert that labelOrCase is one of two known types: [CaseMatch] or
995 // [Label]. We ignore cases, as any users have been resolved to use the 996 // [Label]. We ignore cases, as any users have been resolved to use the
996 // case directly. 997 // case directly.
997 assert(labelOrCase.asLabel() != null); 998 assert(labelOrCase.asLabel() != null);
998 } 999 }
999 } 1000 }
1000 // We ignore the node's statements here, they're generated below in 1001 // We ignore the node's statements here, they're generated below in
1001 // [visitSwitchStatement] once we've set up all the jump targets. 1002 // [visitSwitchStatement] once we've set up all the jump targets.
1002 return new ir.SwitchCase(expressions, null, isDefault: node.isDefaultCase); 1003 return associateNode(new ir.SwitchCase(expressions, null,
1004 isDefault: node.isDefaultCase), node);
1003 } 1005 }
1004 1006
1005 /// Returns true if [node] would let execution reach the next node (aka 1007 /// Returns true if [node] would let execution reach the next node (aka
1006 /// fall-through in switch cases). 1008 /// fall-through in switch cases).
1007 bool fallsThrough(ir.Statement node) { 1009 bool fallsThrough(ir.Statement node) {
1008 return !(node is ir.BreakStatement || 1010 return !(node is ir.BreakStatement ||
1009 node is ir.ReturnStatement || 1011 node is ir.ReturnStatement ||
1010 node is ir.ContinueSwitchStatement || 1012 node is ir.ContinueSwitchStatement ||
1011 (node is ir.ExpressionStatement && node.expression is ir.Throw)); 1013 (node is ir.ExpressionStatement && node.expression is ir.Throw));
1012 } 1014 }
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after
2862 : this(null, true, node, initializers); 2864 : this(null, true, node, initializers);
2863 2865
2864 accept(ir.Visitor v) => throw "unsupported"; 2866 accept(ir.Visitor v) => throw "unsupported";
2865 2867
2866 visitChildren(ir.Visitor v) => throw "unsupported"; 2868 visitChildren(ir.Visitor v) => throw "unsupported";
2867 2869
2868 String toString() { 2870 String toString() {
2869 return "IrFunction($kind, $isConstructor, $node, $initializers)"; 2871 return "IrFunction($kind, $isConstructor, $node, $initializers)";
2870 } 2872 }
2871 } 2873 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/resolution/members.dart » ('j') | pkg/compiler/lib/src/resolution/members.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698