| 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 Unparser implements Visitor { | 5 class Unparser implements Visitor { |
| 6 StringBuffer sb; | 6 StringBuffer sb; |
| 7 final bool printDebugInfo; | 7 final bool printDebugInfo; |
| 8 | 8 |
| 9 Unparser([this.printDebugInfo = false]); | 9 Unparser([this.printDebugInfo = false]); |
| 10 | 10 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 340 |
| 341 visitSwitchStatement(SwitchStatement node) { | 341 visitSwitchStatement(SwitchStatement node) { |
| 342 add(node.switchKeyword.value); | 342 add(node.switchKeyword.value); |
| 343 sb.add(' '); | 343 sb.add(' '); |
| 344 visit(node.parenthesizedExpression); | 344 visit(node.parenthesizedExpression); |
| 345 sb.add(' '); | 345 sb.add(' '); |
| 346 visit(node.cases); | 346 visit(node.cases); |
| 347 } | 347 } |
| 348 | 348 |
| 349 visitSwitchCase(SwitchCase node) { | 349 visitSwitchCase(SwitchCase node) { |
| 350 if (node.label !== null) { | 350 Link<Label> labels = node.labels.nodes; |
| 351 visit(node.label); | 351 Link<CaseMatch> cases = node.cases.nodes; |
| 352 sb.add(': '); | 352 // Interleave labels and cases in their original order. |
| 353 while (!labels.isEmpty()) { |
| 354 Label label = labels.head; |
| 355 while (!cases.isEmpty()) { |
| 356 CaseMatch match = cases.head; |
| 357 if (match.colonToken.charOffset < label.colonToken.charOffset) { |
| 358 visit(match); |
| 359 cases = cases.tail; |
| 360 } else { |
| 361 break; |
| 362 } |
| 363 } |
| 364 visit(label); |
| 365 labels = labels.tail; |
| 353 } | 366 } |
| 354 for (Expression expression in node.expressions) { | 367 while (!cases.isEmpty()) { |
| 355 sb.add('case '); | 368 visit(cases.head); |
| 356 visit(expression); | 369 cases = cases.tail; |
| 357 sb.add(': '); | |
| 358 } | 370 } |
| 359 if (node.isDefaultCase) { | 371 if (node.isDefaultCase) { |
| 360 sb.add('default:'); | 372 sb.add('default:'); |
| 361 } | 373 } |
| 362 visit(node.statements); | 374 visit(node.statements); |
| 363 } | 375 } |
| 364 | 376 |
| 365 visitScriptTag(ScriptTag node) { | 377 visitScriptTag(ScriptTag node) { |
| 366 add(node.beginToken.value); | 378 add(node.beginToken.value); |
| 367 visit(node.tag); | 379 visit(node.tag); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 382 visit(node.tryBlock); | 394 visit(node.tryBlock); |
| 383 visit(node.catchBlocks); | 395 visit(node.catchBlocks); |
| 384 if (node.finallyKeyword !== null) { | 396 if (node.finallyKeyword !== null) { |
| 385 sb.add(' '); | 397 sb.add(' '); |
| 386 add(node.finallyKeyword.value); | 398 add(node.finallyKeyword.value); |
| 387 sb.add(' '); | 399 sb.add(' '); |
| 388 visit(node.finallyBlock); | 400 visit(node.finallyBlock); |
| 389 } | 401 } |
| 390 } | 402 } |
| 391 | 403 |
| 404 visitCaseMatch(CaseMatch node) { |
| 405 add(node.caseKeyword.value); |
| 406 sb.add(" "); |
| 407 visit(node.expression); |
| 408 add(node.colonToken.value); |
| 409 } |
| 410 |
| 392 visitCatchBlock(CatchBlock node) { | 411 visitCatchBlock(CatchBlock node) { |
| 393 add(node.catchKeyword.value); | 412 add(node.catchKeyword.value); |
| 394 sb.add(' '); | 413 sb.add(' '); |
| 395 visit(node.formals); | 414 visit(node.formals); |
| 396 sb.add(' '); | 415 sb.add(' '); |
| 397 visit(node.block); | 416 visit(node.block); |
| 398 } | 417 } |
| 399 | 418 |
| 400 visitTypedef(Typedef node) { | 419 visitTypedef(Typedef node) { |
| 401 add(node.typedefKeyword.value); | 420 add(node.typedefKeyword.value); |
| 402 sb.add(' '); | 421 sb.add(' '); |
| 403 if (node.returnType !== null) { | 422 if (node.returnType !== null) { |
| 404 visit(node.returnType); | 423 visit(node.returnType); |
| 405 sb.add(' '); | 424 sb.add(' '); |
| 406 } | 425 } |
| 407 visit(node.name); | 426 visit(node.name); |
| 408 if (node.typeParameters !== null) { | 427 if (node.typeParameters !== null) { |
| 409 visit(node.typeParameters); | 428 visit(node.typeParameters); |
| 410 } | 429 } |
| 411 visit(node.formals); | 430 visit(node.formals); |
| 412 add(node.endToken.value); | 431 add(node.endToken.value); |
| 413 } | 432 } |
| 414 } | 433 } |
| OLD | NEW |