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

Side by Side Diff: lib/compiler/implementation/js/printer.dart

Issue 11090016: Change core lib, dart2js, and more for new optional parameters syntax (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 visit(Node node) { 67 visit(Node node) {
68 if (node.sourcePosition != null) outBuffer.beginMappedRange(); 68 if (node.sourcePosition != null) outBuffer.beginMappedRange();
69 recordSourcePosition(node.sourcePosition); 69 recordSourcePosition(node.sourcePosition);
70 node.accept(this); 70 node.accept(this);
71 recordSourcePosition(node.endSourcePosition); 71 recordSourcePosition(node.endSourcePosition);
72 if (node.sourcePosition != null) outBuffer.endMappedRange(); 72 if (node.sourcePosition != null) outBuffer.endMappedRange();
73 } 73 }
74 74
75 visitCommaSeparated(List<Node> nodes, int hasRequiredType, 75 visitCommaSeparated(List<Node> nodes, int hasRequiredType,
76 [bool newInForInit, bool newAtStatementBegin]) { 76 {bool newInForInit, bool newAtStatementBegin}) {
77 for (int i = 0; i < nodes.length; i++) { 77 for (int i = 0; i < nodes.length; i++) {
78 if (i != 0) { 78 if (i != 0) {
79 atStatementBegin = false; 79 atStatementBegin = false;
80 out(","); 80 out(",");
81 spaceOut(); 81 spaceOut();
82 } 82 }
83 visitNestedExpression(nodes[i], hasRequiredType, 83 visitNestedExpression(nodes[i], hasRequiredType,
84 newInForInit, newAtStatementBegin); 84 newInForInit: newInForInit,
85 newAtStatementBegin: newAtStatementBegin);
85 } 86 }
86 } 87 }
87 88
88 visitAll(List<Node> nodes) { 89 visitAll(List<Node> nodes) {
89 nodes.forEach(visit); 90 nodes.forEach(visit);
90 } 91 }
91 92
92 visitProgram(Program program) { 93 visitProgram(Program program) {
93 visitAll(program.body); 94 visitAll(program.body);
94 } 95 }
95 96
96 bool blockBody(Node body, [bool needsSeparation, bool needsNewline]) { 97 bool blockBody(Node body, {bool needsSeparation, bool needsNewline}) {
97 if (body is Block) { 98 if (body is Block) {
98 spaceOut(); 99 spaceOut();
99 blockOut(body, false, needsNewline); 100 blockOut(body, false, needsNewline);
100 return true; 101 return true;
101 } 102 }
102 if (shouldCompressOutput && needsSeparation) { 103 if (shouldCompressOutput && needsSeparation) {
103 // If [shouldCompressOutput] is false, then the 'lineOut' will insert 104 // If [shouldCompressOutput] is false, then the 'lineOut' will insert
104 // the separation. 105 // the separation.
105 out(" "); 106 out(" ");
106 } else { 107 } else {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 373
373 visitFunctionDeclaration(FunctionDeclaration declaration) { 374 visitFunctionDeclaration(FunctionDeclaration declaration) {
374 VarCollector vars = new VarCollector(); 375 VarCollector vars = new VarCollector();
375 vars.visitFunctionDeclaration(declaration); 376 vars.visitFunctionDeclaration(declaration);
376 indent(); 377 indent();
377 functionOut(declaration.function, declaration.name, vars); 378 functionOut(declaration.function, declaration.name, vars);
378 lineOut(); 379 lineOut();
379 } 380 }
380 381
381 visitNestedExpression(Expression node, int requiredPrecedence, 382 visitNestedExpression(Expression node, int requiredPrecedence,
382 [bool newInForInit, bool newAtStatementBegin]) { 383 {bool newInForInit, bool newAtStatementBegin}) {
383 bool needsParentheses = 384 bool needsParentheses =
384 // a - (b + c). 385 // a - (b + c).
385 (requiredPrecedence != EXPRESSION && 386 (requiredPrecedence != EXPRESSION &&
386 node.precedenceLevel < requiredPrecedence) || 387 node.precedenceLevel < requiredPrecedence) ||
387 // for (a = (x in o); ... ; ... ) { ... } 388 // for (a = (x in o); ... ; ... ) { ... }
388 (newInForInit && node is Binary && (node as Binary).op == "in") || 389 (newInForInit && node is Binary && (node as Binary).op == "in") ||
389 // (function() { ... })(). 390 // (function() { ... })().
390 // ({a: 2, b: 3}.toString()). 391 // ({a: 2, b: 3}.toString()).
391 (newAtStatementBegin && (node is NamedFunction || 392 (newAtStatementBegin && (node is NamedFunction ||
392 node is Fun || 393 node is Fun ||
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 } 975 }
975 codes.add(charCodes.$0 + digit); 976 codes.add(charCodes.$0 + digit);
976 newName = new String.fromCharCodes(codes); 977 newName = new String.fromCharCodes(codes);
977 } 978 }
978 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));
979 nameNumber++; 980 nameNumber++;
980 maps.last()[oldName] = newName; 981 maps.last()[oldName] = newName;
981 return newName; 982 return newName;
982 } 983 }
983 } 984 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | lib/compiler/implementation/js_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698