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

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

Issue 260233003: Remove js.Sequence and use binary comma operator instead. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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: sdk/lib/_internal/compiler/implementation/ssa/codegen.dart
diff --git a/sdk/lib/_internal/compiler/implementation/ssa/codegen.dart b/sdk/lib/_internal/compiler/implementation/ssa/codegen.dart
index 47d42c1b07dc053cf4103d5aac343c9e52dce064..7dca1867dc77070184e6b1ed120df04e8dd18368 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/codegen.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/codegen.dart
@@ -464,7 +464,11 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
} else if (sequenceElements.length == 1) {
return sequenceElements[0];
} else {
- return new js.Sequence(sequenceElements);
+ js.Expression result = sequenceElements.removeLast();
+ while (sequenceElements.isNotEmpty) {
+ result = new js.Binary(',', sequenceElements.removeLast(), result);
+ }
+ return result;
}
}
@@ -779,35 +783,35 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
jsInitialization = generateExpression(initialization);
if (!shouldGroupVarDeclarations &&
delayedVariablesCount < collectedVariableDeclarations.length) {
- // We just added a new delayed variable-declaration. See if we
- // can put in a 'var' in front of the initialization to make it
- // go away.
- List<js.Expression> expressions;
- if (jsInitialization is js.Sequence) {
- js.Sequence sequence = jsInitialization;
- expressions = sequence.expressions;
- } else {
- expressions = <js.Expression>[jsInitialization];
- }
- bool canTransformToVariableDeclaration = true;
- for (js.Expression expression in expressions) {
- bool expressionIsVariableAssignment = false;
+ // We just added a new delayed variable-declaration. See if we can
+ // put in a 'var' in front of the initialization to make it go
+ // away. We walk the 'tree' of comma-operators to find the
+ // expressions and see if they are all assignments that can be
+ // converted into declarations.
+
+ List<js.Assignment> assignments;
+
+ bool allSimpleAssignments(js.Expression expression) {
if (expression is js.Assignment) {
js.Assignment assignment = expression;
if (assignment.leftHandSide is js.VariableUse &&
!assignment.isCompound) {
- expressionIsVariableAssignment = true;
+ if (assignments == null) assignments = <js.Assignment>[];
+ assignments.add(expression);
+ return true;
}
+ } else if (expression.isCommaOperator) {
+ js.Binary binary = expression;
+ return allSimpleAssignments(binary.left)
+ && allSimpleAssignments(binary.right);
}
- if (!expressionIsVariableAssignment) {
- canTransformToVariableDeclaration = false;
- break;
- }
+ return false;
}
- if (canTransformToVariableDeclaration) {
+
+ if (allSimpleAssignments(jsInitialization)) {
List<js.VariableInitialization> inits =
<js.VariableInitialization>[];
- for (js.Assignment assignment in expressions) {
+ for (js.Assignment assignment in assignments) {
String id = (assignment.leftHandSide as js.VariableUse).name;
js.Node declaration = new js.VariableDeclaration(id);
inits.add(new js.VariableInitialization(declaration,
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js/template.dart ('k') | tests/compiler/dart2js/js_parser_statements_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698