| 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 part of js; | 5 part of js; |
| 6 | 6 |
| 7 class Printer implements NodeVisitor { | 7 class Printer implements NodeVisitor { |
| 8 final bool shouldCompressOutput; | 8 final bool shouldCompressOutput; |
| 9 leg.Compiler compiler; | 9 leg.Compiler compiler; |
| 10 leg.CodeBuffer outBuffer; | 10 leg.CodeBuffer outBuffer; |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 visit(node); | 474 visit(node); |
| 475 } | 475 } |
| 476 } | 476 } |
| 477 | 477 |
| 478 visitVariableDeclarationList(VariableDeclarationList list) { | 478 visitVariableDeclarationList(VariableDeclarationList list) { |
| 479 out("var "); | 479 out("var "); |
| 480 visitCommaSeparated(list.declarations, ASSIGNMENT, | 480 visitCommaSeparated(list.declarations, ASSIGNMENT, |
| 481 newInForInit: inForInit, newAtStatementBegin: false); | 481 newInForInit: inForInit, newAtStatementBegin: false); |
| 482 } | 482 } |
| 483 | 483 |
| 484 visitSequence(Sequence sequence) { | |
| 485 // Note that we only require that the entries are expressions and not | |
| 486 // assignments. This means that nested sequences are not put into | |
| 487 // parenthesis. | |
| 488 visitCommaSeparated(sequence.expressions, EXPRESSION, | |
| 489 newInForInit: false, | |
| 490 newAtStatementBegin: atStatementBegin); | |
| 491 } | |
| 492 | |
| 493 visitAssignment(Assignment assignment) { | 484 visitAssignment(Assignment assignment) { |
| 494 visitNestedExpression(assignment.leftHandSide, LEFT_HAND_SIDE, | 485 visitNestedExpression(assignment.leftHandSide, LEFT_HAND_SIDE, |
| 495 newInForInit: inForInit, | 486 newInForInit: inForInit, |
| 496 newAtStatementBegin: atStatementBegin); | 487 newAtStatementBegin: atStatementBegin); |
| 497 if (assignment.value != null) { | 488 if (assignment.value != null) { |
| 498 spaceOut(); | 489 spaceOut(); |
| 499 String op = assignment.op; | 490 String op = assignment.op; |
| 500 if (op != null) out(op); | 491 if (op != null) out(op); |
| 501 out("="); | 492 out("="); |
| 502 spaceOut(); | 493 spaceOut(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 540 |
| 550 visitBinary(Binary binary) { | 541 visitBinary(Binary binary) { |
| 551 Expression left = binary.left; | 542 Expression left = binary.left; |
| 552 Expression right = binary.right; | 543 Expression right = binary.right; |
| 553 String op = binary.op; | 544 String op = binary.op; |
| 554 int leftPrecedenceRequirement; | 545 int leftPrecedenceRequirement; |
| 555 int rightPrecedenceRequirement; | 546 int rightPrecedenceRequirement; |
| 556 bool leftSpace = true; // left<HERE>op right | 547 bool leftSpace = true; // left<HERE>op right |
| 557 switch (op) { | 548 switch (op) { |
| 558 case ',': | 549 case ',': |
| 550 // x, (y, z) <=> (x, y), z. |
| 559 leftPrecedenceRequirement = EXPRESSION; | 551 leftPrecedenceRequirement = EXPRESSION; |
| 560 rightPrecedenceRequirement = LOGICAL_OR; | 552 rightPrecedenceRequirement = EXPRESSION; |
| 561 leftSpace = false; | 553 leftSpace = false; |
| 562 break; | 554 break; |
| 563 case "||": | 555 case "||": |
| 564 leftPrecedenceRequirement = LOGICAL_OR; | 556 leftPrecedenceRequirement = LOGICAL_OR; |
| 565 // x || (y || z) <=> (x || y) || z. | 557 // x || (y || z) <=> (x || y) || z. |
| 566 rightPrecedenceRequirement = LOGICAL_OR; | 558 rightPrecedenceRequirement = LOGICAL_OR; |
| 567 break; | 559 break; |
| 568 case "&&": | 560 case "&&": |
| 569 leftPrecedenceRequirement = LOGICAL_AND; | 561 leftPrecedenceRequirement = LOGICAL_AND; |
| 570 // x && (y && z) <=> (x && y) && z. | 562 // x && (y && z) <=> (x && y) && z. |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); | 1160 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); |
| 1169 } | 1161 } |
| 1170 codes.add(charCodes.$0 + digit); | 1162 codes.add(charCodes.$0 + digit); |
| 1171 newName = new String.fromCharCodes(codes); | 1163 newName = new String.fromCharCodes(codes); |
| 1172 } | 1164 } |
| 1173 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); | 1165 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
| 1174 maps.last[oldName] = newName; | 1166 maps.last[oldName] = newName; |
| 1175 return newName; | 1167 return newName; |
| 1176 } | 1168 } |
| 1177 } | 1169 } |
| OLD | NEW |