| 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 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 rightPrecedenceRequirement = MULTIPLICATIVE; | 612 rightPrecedenceRequirement = MULTIPLICATIVE; |
| 613 break; | 613 break; |
| 614 case "*": | 614 case "*": |
| 615 case "/": | 615 case "/": |
| 616 case "%": | 616 case "%": |
| 617 leftPrecedenceRequirement = MULTIPLICATIVE; | 617 leftPrecedenceRequirement = MULTIPLICATIVE; |
| 618 // We cannot remove parenthesis for "*" because of precision issues. | 618 // We cannot remove parenthesis for "*" because of precision issues. |
| 619 rightPrecedenceRequirement = UNARY; | 619 rightPrecedenceRequirement = UNARY; |
| 620 break; | 620 break; |
| 621 default: | 621 default: |
| 622 compiler.internalError("Forgot operator: $op"); | 622 compiler.internalError(NO_LOCATION_SPANNABLE, "Forgot operator: $op"); |
| 623 } | 623 } |
| 624 | 624 |
| 625 visitNestedExpression(left, leftPrecedenceRequirement, | 625 visitNestedExpression(left, leftPrecedenceRequirement, |
| 626 newInForInit: inForInit, | 626 newInForInit: inForInit, |
| 627 newAtStatementBegin: atStatementBegin); | 627 newAtStatementBegin: atStatementBegin); |
| 628 | 628 |
| 629 if (op == "in" || op == "instanceof") { | 629 if (op == "in" || op == "instanceof") { |
| 630 // There are cases where the space is not required but without further | 630 // There are cases where the space is not required but without further |
| 631 // analysis we cannot know. | 631 // analysis we cannot know. |
| 632 out(" "); | 632 out(" "); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 out(node.pattern); | 849 out(node.pattern); |
| 850 } | 850 } |
| 851 | 851 |
| 852 visitLiteralExpression(LiteralExpression node) { | 852 visitLiteralExpression(LiteralExpression node) { |
| 853 String template = node.template; | 853 String template = node.template; |
| 854 List<Expression> inputs = node.inputs; | 854 List<Expression> inputs = node.inputs; |
| 855 | 855 |
| 856 List<String> parts = template.split('#'); | 856 List<String> parts = template.split('#'); |
| 857 int inputsLength = inputs == null ? 0 : inputs.length; | 857 int inputsLength = inputs == null ? 0 : inputs.length; |
| 858 if (parts.length != inputsLength + 1) { | 858 if (parts.length != inputsLength + 1) { |
| 859 compiler.internalError('Wrong number of arguments for JS: $template'); | 859 compiler.internalError(NO_LOCATION_SPANNABLE, |
| 860 'Wrong number of arguments for JS: $template'); |
| 860 } | 861 } |
| 861 // Code that uses JS must take care of operator precedences, and | 862 // Code that uses JS must take care of operator precedences, and |
| 862 // put parenthesis if needed. | 863 // put parenthesis if needed. |
| 863 out(parts[0]); | 864 out(parts[0]); |
| 864 for (int i = 0; i < inputsLength; i++) { | 865 for (int i = 0; i < inputsLength; i++) { |
| 865 visit(inputs[i]); | 866 visit(inputs[i]); |
| 866 out(parts[i + 1]); | 867 out(parts[i + 1]); |
| 867 } | 868 } |
| 868 } | 869 } |
| 869 | 870 |
| 870 visitLiteralStatement(LiteralStatement node) { | 871 visitLiteralStatement(LiteralStatement node) { |
| 871 outLn(node.code); | 872 outLn(node.code); |
| 872 } | 873 } |
| 873 | 874 |
| 874 visitJSExpression(JSExpression node) { | 875 visitJSExpression(JSExpression node) { |
| 875 compiler.internalError('JSPrinter should never see a JSExpression'); | 876 compiler.internalError(NO_LOCATION_SPANNABLE, |
| 877 'JSPrinter should never see a JSExpression.'); |
| 876 } | 878 } |
| 877 | 879 |
| 878 visitInterpolatedExpression(InterpolatedExpression node) { | 880 visitInterpolatedExpression(InterpolatedExpression node) { |
| 879 visit(node.value); | 881 visit(node.value); |
| 880 } | 882 } |
| 881 | 883 |
| 882 void visitComment(Comment node) { | 884 void visitComment(Comment node) { |
| 883 if (shouldCompressOutput) return; | 885 if (shouldCompressOutput) return; |
| 884 String comment = node.comment.trim(); | 886 String comment = node.comment.trim(); |
| 885 if (comment.isEmpty) return; | 887 if (comment.isEmpty) return; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 * as then-statement in an [If] that has an else branch. | 968 * as then-statement in an [If] that has an else branch. |
| 967 */ | 969 */ |
| 968 class DanglingElseVisitor extends BaseVisitor<bool> { | 970 class DanglingElseVisitor extends BaseVisitor<bool> { |
| 969 leg.Compiler compiler; | 971 leg.Compiler compiler; |
| 970 | 972 |
| 971 DanglingElseVisitor(this.compiler); | 973 DanglingElseVisitor(this.compiler); |
| 972 | 974 |
| 973 bool visitProgram(Program node) => false; | 975 bool visitProgram(Program node) => false; |
| 974 | 976 |
| 975 bool visitNode(Statement node) { | 977 bool visitNode(Statement node) { |
| 976 compiler.internalError("Forgot node: $node"); | 978 compiler.internalError(NO_LOCATION_SPANNABLE, "Forgot node: $node"); |
| 977 return null; | 979 return null; |
| 978 } | 980 } |
| 979 | 981 |
| 980 bool visitBlock(Block node) => false; | 982 bool visitBlock(Block node) => false; |
| 981 bool visitExpressionStatement(ExpressionStatement node) => false; | 983 bool visitExpressionStatement(ExpressionStatement node) => false; |
| 982 bool visitEmptyStatement(EmptyStatement node) => false; | 984 bool visitEmptyStatement(EmptyStatement node) => false; |
| 983 bool visitIf(If node) { | 985 bool visitIf(If node) { |
| 984 if (!node.hasElse) return true; | 986 if (!node.hasElse) return true; |
| 985 return node.otherwise.accept(this); | 987 return node.otherwise.accept(this); |
| 986 } | 988 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); | 1145 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); |
| 1144 } | 1146 } |
| 1145 codes.add(charCodes.$0 + digit); | 1147 codes.add(charCodes.$0 + digit); |
| 1146 newName = new String.fromCharCodes(codes); | 1148 newName = new String.fromCharCodes(codes); |
| 1147 } | 1149 } |
| 1148 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); | 1150 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
| 1149 maps.last[oldName] = newName; | 1151 maps.last[oldName] = newName; |
| 1150 return newName; | 1152 return newName; |
| 1151 } | 1153 } |
| 1152 } | 1154 } |
| OLD | NEW |