OLD | NEW |
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 library rasta.kernel_visitor; | 5 library rasta.kernel_visitor; |
6 | 6 |
7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
8 | 8 |
9 import 'package:kernel/frontend/accessors.dart' show | 9 import 'package:kernel/frontend/accessors.dart' show |
10 Accessor, | 10 Accessor, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 import 'unresolved.dart' show | 169 import 'unresolved.dart' show |
170 RastaUnresolved; | 170 RastaUnresolved; |
171 | 171 |
172 import 'error.dart' show | 172 import 'error.dart' show |
173 RastaError; | 173 RastaError; |
174 | 174 |
175 import 'kernel.dart' show | 175 import 'kernel.dart' show |
176 ConstructorTarget, | 176 ConstructorTarget, |
177 Kernel; | 177 Kernel; |
178 | 178 |
| 179 import 'kernel/fall_through_visitor.dart' show |
| 180 fallsThrough; |
| 181 |
179 /// Translates dart2js AST nodes [Node] into Kernel IR [ir.TreeNode]. | 182 /// Translates dart2js AST nodes [Node] into Kernel IR [ir.TreeNode]. |
180 /// | 183 /// |
181 /// Most methods in this class have a prefix that follows these conventions: | 184 /// Most methods in this class have a prefix that follows these conventions: |
182 /// | 185 /// |
183 /// * `visit` for overridden visitor methods. | 186 /// * `visit` for overridden visitor methods. |
184 /// * `handle` for methods that implement common behavior for several `visit` | 187 /// * `handle` for methods that implement common behavior for several `visit` |
185 /// methods. These methods are called by `visit` methods implemented by | 188 /// methods. These methods are called by `visit` methods implemented by |
186 /// various mixins below. | 189 /// various mixins below. |
187 /// * `build` helper method that builds a new Kernel IR tree. | 190 /// * `build` helper method that builds a new Kernel IR tree. |
188 /// * `get` helper method that use a cache to build exactly one Kernel IR | 191 /// * `get` helper method that use a cache to build exactly one Kernel IR |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 internalError(caseNode, "case node mismatch"); | 1038 internalError(caseNode, "case node mismatch"); |
1036 } | 1039 } |
1037 ir.SwitchCase irCase = casesIterator.current; | 1040 ir.SwitchCase irCase = casesIterator.current; |
1038 List<ir.Statement> statements = <ir.Statement>[]; | 1041 List<ir.Statement> statements = <ir.Statement>[]; |
1039 bool hasVariableDeclaration = false; | 1042 bool hasVariableDeclaration = false; |
1040 for (Statement statement in caseNode.statements.nodes) { | 1043 for (Statement statement in caseNode.statements.nodes) { |
1041 if (buildStatement(statement, statements)) { | 1044 if (buildStatement(statement, statements)) { |
1042 hasVariableDeclaration = true; | 1045 hasVariableDeclaration = true; |
1043 } | 1046 } |
1044 } | 1047 } |
| 1048 if (statements.isEmpty || fallsThrough(statements.last)) { |
| 1049 statements.add( |
| 1050 new ir.ExpressionStatement( |
| 1051 new ir.Throw( |
| 1052 new ir.StaticInvocation( |
| 1053 kernel.getFallThroughErrorBuilder(), |
| 1054 new ir.Arguments.empty())))); |
| 1055 } |
1045 ir.Statement body; | 1056 ir.Statement body; |
1046 if (!hasVariableDeclaration && statements.length == 1) { | 1057 if (!hasVariableDeclaration && statements.length == 1) { |
1047 body = statements.single; | 1058 body = statements.single; |
1048 } else { | 1059 } else { |
1049 body = new ir.Block(statements); | 1060 body = new ir.Block(statements); |
1050 } | 1061 } |
1051 irCase.body = body; | 1062 irCase.body = body; |
1052 body.parent = irCase; | 1063 body.parent = irCase; |
1053 } | 1064 } |
1054 assert(!casesIterator.moveNext()); | 1065 assert(!casesIterator.moveNext()); |
(...skipping 1983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3038 : this(null, true, node, initializers); | 3049 : this(null, true, node, initializers); |
3039 | 3050 |
3040 accept(ir.Visitor v) => throw "unsupported"; | 3051 accept(ir.Visitor v) => throw "unsupported"; |
3041 | 3052 |
3042 visitChildren(ir.Visitor v) => throw "unsupported"; | 3053 visitChildren(ir.Visitor v) => throw "unsupported"; |
3043 | 3054 |
3044 String toString() { | 3055 String toString() { |
3045 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 3056 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
3046 } | 3057 } |
3047 } | 3058 } |
OLD | NEW |