| 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 final Renamer renamer; | 6 final Renamer renamer; |
| 7 StringBuffer sb; | 7 StringBuffer sb; |
| 8 | 8 |
| 9 Unparser([this.renamer = const Renamer()]); | 9 Unparser([this.renamer = const Renamer()]); |
| 10 | 10 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 sb.add(' '); | 99 sb.add(' '); |
| 100 } | 100 } |
| 101 if (node.getOrSet !== null) { | 101 if (node.getOrSet !== null) { |
| 102 add(node.getOrSet.value); | 102 add(node.getOrSet.value); |
| 103 sb.add(' '); | 103 sb.add(' '); |
| 104 } | 104 } |
| 105 // TODO(antonm): that's a workaround as currently FunctionExpression | 105 // TODO(antonm): that's a workaround as currently FunctionExpression |
| 106 // names are modelled with Send and it emits operator[] as only | 106 // names are modelled with Send and it emits operator[] as only |
| 107 // operator, without [] which are expected to be emitted with | 107 // operator, without [] which are expected to be emitted with |
| 108 // arguments. | 108 // arguments. |
| 109 emitName(Identifier name) { | |
| 110 final newName = renamer.renameIdentifier(name); | |
| 111 if (newName === null) { | |
| 112 visit(name); | |
| 113 } else { | |
| 114 sb.add(newName); | |
| 115 } | |
| 116 } | |
| 117 if (node.name is Send) { | 109 if (node.name is Send) { |
| 118 Send send = node.name; | 110 Send send = node.name; |
| 119 assert(send is !SendSet); | 111 assert(send is !SendSet); |
| 120 if (!send.isOperator) { | 112 if (!send.isOperator) { |
| 121 // Looks like a factory method. | 113 // Looks like a factory method. |
| 122 emitName(send.receiver); | 114 visit(send.receiver); |
| 123 sb.add('.'); | 115 sb.add('.'); |
| 124 } else { | 116 } else { |
| 125 visit(send.receiver); | 117 visit(send.receiver); |
| 126 if (send.selector.token.kind === KEYWORD_TOKEN) sb.add(' '); | 118 if (send.selector.token.kind === KEYWORD_TOKEN) sb.add(' '); |
| 127 } | 119 } |
| 128 visit(send.selector); | 120 visit(send.selector); |
| 129 } else { | 121 } else { |
| 130 if (node.name !== null) emitName(node.name); | 122 visit(node.name); |
| 131 } | 123 } |
| 132 visit(node.parameters); | 124 visit(node.parameters); |
| 133 visit(node.initializers); | 125 visit(node.initializers); |
| 134 visit(node.body); | 126 visit(node.body); |
| 135 } | 127 } |
| 136 | 128 |
| 137 visitIdentifier(Identifier node) { | 129 visitIdentifier(Identifier node) { |
| 138 add(node.token.value); | 130 String newName = renamer.renameIdentifier(node); |
| 131 if (newName === null) { |
| 132 add(node.token.value); |
| 133 } else { |
| 134 sb.add(newName); |
| 135 } |
| 139 } | 136 } |
| 140 | 137 |
| 141 visitIf(If node) { | 138 visitIf(If node) { |
| 142 add(node.ifToken.value); | 139 add(node.ifToken.value); |
| 143 visit(node.condition); | 140 visit(node.condition); |
| 144 visit(node.thenPart); | 141 visit(node.thenPart); |
| 145 if (node.hasElsePart) { | 142 if (node.hasElsePart) { |
| 146 addToken(node.elseToken); | 143 addToken(node.elseToken); |
| 147 visit(node.elsePart); | 144 visit(node.elsePart); |
| 148 } | 145 } |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 sb.add(' '); | 507 sb.add(' '); |
| 511 } | 508 } |
| 512 visit(node.name); | 509 visit(node.name); |
| 513 if (node.typeParameters !== null) { | 510 if (node.typeParameters !== null) { |
| 514 visit(node.typeParameters); | 511 visit(node.typeParameters); |
| 515 } | 512 } |
| 516 visit(node.formals); | 513 visit(node.formals); |
| 517 add(node.endToken.value); | 514 add(node.endToken.value); |
| 518 } | 515 } |
| 519 } | 516 } |
| OLD | NEW |