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 class Printer implements NodeVisitor { | 5 class Printer implements NodeVisitor { |
6 final bool shouldCompressOutput; | 6 final bool shouldCompressOutput; |
7 leg.Compiler compiler; | 7 leg.Compiler compiler; |
8 leg.CodeBuffer outBuffer; | 8 leg.CodeBuffer outBuffer; |
9 int indentLevel = 0; | 9 int indentLevel = 0; |
10 bool inForInit = false; | 10 bool inForInit = false; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 visitAll(node.cases); | 324 visitAll(node.cases); |
325 indentLevel--; | 325 indentLevel--; |
326 outIndentLn("}"); | 326 outIndentLn("}"); |
327 } | 327 } |
328 | 328 |
329 visitCase(Case node) { | 329 visitCase(Case node) { |
330 outIndent("case "); | 330 outIndent("case "); |
331 visitNestedExpression(node.expression, EXPRESSION, | 331 visitNestedExpression(node.expression, EXPRESSION, |
332 newInForInit: false, newAtStatementBegin: false); | 332 newInForInit: false, newAtStatementBegin: false); |
333 outLn(":"); | 333 outLn(":"); |
334 if (!node.body.statements.isEmpty()) { | 334 if (!node.body.statements.isEmpty) { |
335 indentLevel++; | 335 indentLevel++; |
336 blockOutWithoutBraces(node.body); | 336 blockOutWithoutBraces(node.body); |
337 indentLevel--; | 337 indentLevel--; |
338 } | 338 } |
339 } | 339 } |
340 | 340 |
341 visitDefault(Default node) { | 341 visitDefault(Default node) { |
342 outIndentLn("default:"); | 342 outIndentLn("default:"); |
343 if (!node.body.statements.isEmpty()) { | 343 if (!node.body.statements.isEmpty) { |
344 indentLevel++; | 344 indentLevel++; |
345 blockOutWithoutBraces(node.body); | 345 blockOutWithoutBraces(node.body); |
346 indentLevel--; | 346 indentLevel--; |
347 } | 347 } |
348 } | 348 } |
349 | 349 |
350 visitLabeledStatement(LabeledStatement node) { | 350 visitLabeledStatement(LabeledStatement node) { |
351 outIndent("${node.label}:"); | 351 outIndent("${node.label}:"); |
352 blockBody(node.body, needsSeparation: false, needsNewline: true); | 352 blockBody(node.body, needsSeparation: false, needsNewline: true); |
353 } | 353 } |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 return oldName; | 938 return oldName; |
939 } | 939 } |
940 | 940 |
941 static int nthLetter(int n) { | 941 static int nthLetter(int n) { |
942 return (n < 26) ? charCodes.$a + n : charCodes.$A + n - 26; | 942 return (n < 26) ? charCodes.$a + n : charCodes.$A + n - 26; |
943 } | 943 } |
944 | 944 |
945 String declareName(String oldName) { | 945 String declareName(String oldName) { |
946 const LETTERS = 52; | 946 const LETTERS = 52; |
947 const DIGITS = 10; | 947 const DIGITS = 10; |
948 if (maps.isEmpty()) return oldName; | 948 if (maps.isEmpty) return oldName; |
949 | 949 |
950 String newName; | 950 String newName; |
951 int n = nameNumber; | 951 int n = nameNumber; |
952 if (n < LETTERS) { | 952 if (n < LETTERS) { |
953 // Start naming variables a, b, c, ..., z, A, B, C, ..., Z. | 953 // Start naming variables a, b, c, ..., z, A, B, C, ..., Z. |
954 newName = new String.fromCharCodes([nthLetter(n)]); | 954 newName = new String.fromCharCodes([nthLetter(n)]); |
955 } else { | 955 } else { |
956 // Then name variables a0, a1, a2, ..., a9, b0, b1, ..., Z9, aa0, aa1, ... | 956 // Then name variables a0, a1, a2, ..., a9, b0, b1, ..., Z9, aa0, aa1, ... |
957 // For all functions with fewer than 500 locals this is just as compact | 957 // For all functions with fewer than 500 locals this is just as compact |
958 // as using aa, ab, etc. but avoids clashes with keywords. | 958 // as using aa, ab, etc. but avoids clashes with keywords. |
(...skipping 16 matching lines...) Expand all Loading... |
975 } | 975 } |
976 codes.add(charCodes.$0 + digit); | 976 codes.add(charCodes.$0 + digit); |
977 newName = new String.fromCharCodes(codes); | 977 newName = new String.fromCharCodes(codes); |
978 } | 978 } |
979 assert(const RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); | 979 assert(const RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
980 nameNumber++; | 980 nameNumber++; |
981 maps.last()[oldName] = newName; | 981 maps.last()[oldName] = newName; |
982 return newName; | 982 return newName; |
983 } | 983 } |
984 } | 984 } |
OLD | NEW |