| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
| 8 | 8 |
| 9 import '../closure.dart'; | 9 import '../closure.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 6179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6190 if (switchCases.isEmpty) { | 6190 if (switchCases.isEmpty) { |
| 6191 return; | 6191 return; |
| 6192 } | 6192 } |
| 6193 | 6193 |
| 6194 HSwitch switchInstruction = new HSwitch(<HInstruction>[expression]); | 6194 HSwitch switchInstruction = new HSwitch(<HInstruction>[expression]); |
| 6195 HBasicBlock expressionEnd = close(switchInstruction); | 6195 HBasicBlock expressionEnd = close(switchInstruction); |
| 6196 LocalsHandler savedLocals = localsHandler; | 6196 LocalsHandler savedLocals = localsHandler; |
| 6197 | 6197 |
| 6198 List<HStatementInformation> statements = <HStatementInformation>[]; | 6198 List<HStatementInformation> statements = <HStatementInformation>[]; |
| 6199 bool hasDefault = false; | 6199 bool hasDefault = false; |
| 6200 Element getFallThroughErrorElement = helpers.fallThroughError; | |
| 6201 HasNextIterator<ast.Node> caseIterator = | 6200 HasNextIterator<ast.Node> caseIterator = |
| 6202 new HasNextIterator<ast.Node>(switchCases.iterator); | 6201 new HasNextIterator<ast.Node>(switchCases.iterator); |
| 6203 while (caseIterator.hasNext) { | 6202 while (caseIterator.hasNext) { |
| 6204 ast.SwitchCase switchCase = caseIterator.next(); | 6203 ast.SwitchCase switchCase = caseIterator.next(); |
| 6205 HBasicBlock block = graph.addNewBlock(); | 6204 HBasicBlock block = graph.addNewBlock(); |
| 6206 for (ConstantValue constant in getConstants(switchCase)) { | 6205 for (ConstantValue constant in getConstants(switchCase)) { |
| 6207 HConstant hConstant = graph.addConstant(constant, compiler); | 6206 HConstant hConstant = graph.addConstant(constant, compiler); |
| 6208 switchInstruction.inputs.add(hConstant); | 6207 switchInstruction.inputs.add(hConstant); |
| 6209 hConstant.usedBy.add(switchInstruction); | 6208 hConstant.usedBy.add(switchInstruction); |
| 6210 expressionEnd.addSuccessor(block); | 6209 expressionEnd.addSuccessor(block); |
| 6211 } | 6210 } |
| 6212 | 6211 |
| 6213 if (isDefaultCase(switchCase)) { | 6212 if (isDefaultCase(switchCase)) { |
| 6214 // An HSwitch has n inputs and n+1 successors, the last being the | 6213 // An HSwitch has n inputs and n+1 successors, the last being the |
| 6215 // default case. | 6214 // default case. |
| 6216 expressionEnd.addSuccessor(block); | 6215 expressionEnd.addSuccessor(block); |
| 6217 hasDefault = true; | 6216 hasDefault = true; |
| 6218 } | 6217 } |
| 6219 open(block); | 6218 open(block); |
| 6220 localsHandler = new LocalsHandler.from(savedLocals); | 6219 localsHandler = new LocalsHandler.from(savedLocals); |
| 6221 buildSwitchCase(switchCase); | 6220 buildSwitchCase(switchCase); |
| 6222 if (!isAborted()) { | 6221 if (!isAborted()) { |
| 6223 if (caseIterator.hasNext) { | 6222 if (caseIterator.hasNext && isReachable) { |
| 6224 pushInvokeStatic(switchCase, getFallThroughErrorElement, []); | 6223 pushInvokeStatic(switchCase, helpers.fallThroughError, []); |
| 6225 HInstruction error = pop(); | 6224 HInstruction error = pop(); |
| 6226 closeAndGotoExit(new HThrow(error, error.sourceInformation)); | 6225 closeAndGotoExit(new HThrow(error, error.sourceInformation)); |
| 6227 } else if (!isDefaultCase(switchCase)) { | 6226 } else if (!isDefaultCase(switchCase)) { |
| 6228 // If there is no default, we will add one later to avoid | 6227 // If there is no default, we will add one later to avoid |
| 6229 // the critical edge. So we generate a break statement to make | 6228 // the critical edge. So we generate a break statement to make |
| 6230 // sure the last case does not fall through to the default case. | 6229 // sure the last case does not fall through to the default case. |
| 6231 jumpHandler.generateBreak(); | 6230 jumpHandler.generateBreak(); |
| 6232 } | 6231 } |
| 6233 } | 6232 } |
| 6234 statements.add( | 6233 statements.add( |
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7046 if (unaliased is TypedefType) throw 'unable to unalias $type'; | 7045 if (unaliased is TypedefType) throw 'unable to unalias $type'; |
| 7047 unaliased.accept(this, builder); | 7046 unaliased.accept(this, builder); |
| 7048 } | 7047 } |
| 7049 | 7048 |
| 7050 void visitDynamicType(DynamicType type, SsaBuilder builder) { | 7049 void visitDynamicType(DynamicType type, SsaBuilder builder) { |
| 7051 JavaScriptBackend backend = builder.compiler.backend; | 7050 JavaScriptBackend backend = builder.compiler.backend; |
| 7052 ClassElement cls = backend.helpers.DynamicRuntimeType; | 7051 ClassElement cls = backend.helpers.DynamicRuntimeType; |
| 7053 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld))); | 7052 builder.push(new HDynamicType(type, new TypeMask.exact(cls, closedWorld))); |
| 7054 } | 7053 } |
| 7055 } | 7054 } |
| OLD | NEW |