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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1191193005: Implement simple switch statements as nested if/else. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update status files, and merge. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
index 88373676a4111b53ab6a16f33315c9ffc173020b..aebd19dbd5fa85b098d1f1d28049b93dde0091cc 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
@@ -390,6 +390,48 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
return null;
}
+ visitSwitchStatement(ast.SwitchStatement node) {
+ assert(irBuilder.isOpen);
+ // We do not handle switch statements with continue to labeled cases.
+ for (ast.SwitchCase switchCase in node.cases) {
+ for (ast.Node labelOrCase in switchCase.labelsAndCases) {
+ if (labelOrCase is ast.Label) {
+ LabelDefinition definition = elements.getLabelDefinition(labelOrCase);
+ if (definition != null && definition.isContinueTarget) {
+ return giveup(node, "continue to a labeled switch case");
+ }
+ }
+ }
+ }
+
+ // Each switch case contains a list of interleaved labels and expressions
+ // and a non-empty body. We can ignore the labels because they are not
+ // jump targets.
+ List<SwitchCaseInfo> cases = <SwitchCaseInfo>[];
+ SwitchCaseInfo defaultCase;
+ for (ast.SwitchCase switchCase in node.cases) {
+ SwitchCaseInfo caseInfo =
+ new SwitchCaseInfo(subbuildSequence(switchCase.statements));
+ if (switchCase.isDefaultCase) {
+ defaultCase = caseInfo;
+ } else {
+ cases.add(caseInfo);
+ for (ast.Node labelOrCase in switchCase.labelsAndCases) {
+ if (labelOrCase is ast.CaseMatch) {
+ ir.Primitive constant = translateConstant(labelOrCase.expression);
+ caseInfo.addConstant(constant);
+ }
+ }
+ }
+ }
+ ir.Primitive value = visit(node.expression);
+ JumpTarget target = elements.getTargetDefinition(node);
+ Element error =
+ (compiler.backend as JavaScriptBackend).getFallThroughError();
+ irBuilder.buildSimpleSwitch(target, value, cases, defaultCase, error,
+ sourceInformationBuilder.buildGeneric(node));
+ }
+
visitTryStatement(ast.TryStatement node) {
// Finally blocks are not yet implemented.
if (node.finallyBlock != null) {
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698