Chromium Code Reviews| Index: lib/compiler/implementation/ssa/codegen.dart |
| diff --git a/lib/compiler/implementation/ssa/codegen.dart b/lib/compiler/implementation/ssa/codegen.dart |
| index e4437cf32676fd576ae0f599a32e9e656bff0308..75fd55859be315f98663c124b203fa899f8faf31 100644 |
| --- a/lib/compiler/implementation/ssa/codegen.dart |
| +++ b/lib/compiler/implementation/ssa/codegen.dart |
| @@ -633,6 +633,44 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor { |
| return true; |
| } |
| + bool visitSwitchInfo(HSwitchBlockInformation info) { |
| + bool isExpression = isJSExpression(info.expression); |
| + if (!isExpression) { |
| + generateStatements(info.expression); |
| + } |
| + addIndentation(); |
| + for (LabelElement label in info.labels) { |
| + if (label.isTarget) { |
| + writeLabel(label); |
| + buffer.add(":"); |
| + } |
| + } |
| + addIndented("switch ("); |
| + if (isExpression) { |
| + generateExpression(info.expression); |
| + } else { |
| + use(info.expression.conditionExpression, JSPrecedence.EXPRESSION_PRECEDENCE); |
|
floitsch
2012/06/06 11:50:26
80chars.
Lasse Reichstein Nielsen
2012/06/06 13:01:21
Done.
|
| + } |
| + buffer.add(") {\n"); |
| + indent++; |
| + for (int i = 0; i < info.matchExpressions.length; i++) { |
| + for (Constant constant in info.matchExpressions[i]) { |
| + addIndented("case "); |
| + generateConstant(constant); |
| + buffer.add(":\n"); |
| + } |
| + if (i == info.matchExpressions.length - 1 && info.hasDefault) { |
| + addIndented("default:\n"); |
| + } |
| + indent++; |
| + generateStatements(info.statements[i]); |
| + indent--; |
| + } |
| + indent--; |
| + addIndented("}\n"); |
| + return true; |
| + } |
| + |
| bool visitSequenceInfo(HStatementSequenceInformation info) { |
| return false; |
| } |
| @@ -1567,28 +1605,33 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor { |
| endExpression(JSPrecedence.MEMBER_PRECEDENCE); |
| } |
| - visitConstant(HConstant node) { |
| - assert(isGenerateAtUseSite(node)); |
| + void generateConstant(Constant constant) { |
| // TODO(floitsch): the compile-time constant handler and the codegen |
| // need to work together to avoid the parenthesis. See r4928 for an |
| // implementation that still dealt with precedence. |
| ConstantHandler handler = compiler.constantHandler; |
| - String name = handler.getNameForConstant(node.constant); |
| + String name = handler.getNameForConstant(constant); |
| if (name === null) { |
| - assert(!node.constant.isObject()); |
| - if (node.constant.isNum() |
| + assert(!constant.isObject()); |
| + if (constant.isNum() |
| && expectedPrecedence == JSPrecedence.MEMBER_PRECEDENCE) { |
| buffer.add('('); |
| - handler.writeConstant(buffer, node.constant); |
| + handler.writeConstant(buffer, constant); |
| buffer.add(')'); |
| } else { |
| - handler.writeConstant(buffer, node.constant); |
| + handler.writeConstant(buffer, constant); |
| } |
| } else { |
| buffer.add(compiler.namer.CURRENT_ISOLATE); |
| buffer.add("."); |
| buffer.add(name); |
| } |
| + |
| + } |
| + |
| + visitConstant(HConstant node) { |
| + assert(isGenerateAtUseSite(node)); |
| + generateConstant(node.constant); |
| } |
| visitLoopBranch(HLoopBranch node) { |
| @@ -1796,6 +1839,10 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor { |
| buffer.add(text); |
| } |
| + void visitSwitch(HSwitch node) { |
| + // Switches are handled using [visitSwitchInfo]. |
| + } |
| + |
| void visitStatic(HStatic node) { |
| world.registerStaticUse(node.element); |
| buffer.add(compiler.namer.isolateAccess(node.element)); |