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

Unified Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10544024: Implement constant switch as JS switch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
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));

Powered by Google App Engine
This is Rietveld 408576698