Chromium Code Reviews| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 sb.add(' '); | 93 sb.add(' '); |
| 94 } | 94 } |
| 95 if (node.getOrSet !== null) { | 95 if (node.getOrSet !== null) { |
| 96 add(node.getOrSet.value); | 96 add(node.getOrSet.value); |
| 97 sb.add(' '); | 97 sb.add(' '); |
| 98 } | 98 } |
| 99 // TODO(antonm): that's a workaround as currently FunctionExpression | 99 // TODO(antonm): that's a workaround as currently FunctionExpression |
| 100 // names are modelled with Send and it emits operator[] as only | 100 // names are modelled with Send and it emits operator[] as only |
| 101 // operator, without [] which are expected to be emitted with | 101 // operator, without [] which are expected to be emitted with |
| 102 // arguments. | 102 // arguments. |
| 103 emitName(Identifier name) { | |
| 104 final newName = renamer.renameIdentifier(name); | |
|
Roman
2012/08/02 05:44:53
Looks like now renameIdentifier is only used for f
Anton Muhin
2012/08/03 13:57:57
It should be used for getters/setters, maybe even
| |
| 105 if (newName === null) { | |
| 106 visit(name); | |
| 107 } else { | |
| 108 sb.add(newName); | |
| 109 } | |
| 110 } | |
| 103 if (node.name is Send) { | 111 if (node.name is Send) { |
| 104 Send send = node.name; | 112 Send send = node.name; |
| 105 assert(send is !SendSet); | 113 assert(send is !SendSet); |
| 106 visit(send.receiver); | |
| 107 if (!send.isOperator) { | 114 if (!send.isOperator) { |
| 108 // Looks like a factory method. | 115 // Looks like a factory method. |
| 116 emitName(send.receiver); | |
| 109 sb.add('.'); | 117 sb.add('.'); |
| 118 } else { | |
| 119 visit(send.receiver); | |
| 110 } | 120 } |
| 111 visit(send.selector); | 121 visit(send.selector); |
| 112 } else { | 122 } else { |
| 113 visit(node.name); | 123 if (node.name !== null) emitName(node.name); |
| 114 } | 124 } |
| 115 visit(node.parameters); | 125 visit(node.parameters); |
| 116 visit(node.initializers); | 126 visit(node.initializers); |
| 117 visit(node.body); | 127 visit(node.body); |
| 118 } | 128 } |
| 119 | 129 |
| 120 visitIdentifier(Identifier node) { | 130 visitIdentifier(Identifier node) { |
| 121 String newName = renamer.renameIdentifier(node); | 131 add(node.token.value); |
| 122 if (newName == null) { | |
| 123 add(node.token.value); | |
| 124 } else { | |
| 125 sb.add(newName); | |
| 126 } | |
| 127 } | 132 } |
| 128 | 133 |
| 129 visitIf(If node) { | 134 visitIf(If node) { |
| 130 add(node.ifToken.value); | 135 add(node.ifToken.value); |
| 131 visit(node.condition); | 136 visit(node.condition); |
| 132 visit(node.thenPart); | 137 visit(node.thenPart); |
| 133 if (node.hasElsePart) { | 138 if (node.hasElsePart) { |
| 134 add(node.elseToken.value); | 139 add(node.elseToken.value); |
| 135 sb.add(' '); | 140 sb.add(' '); |
| 136 visit(node.elsePart); | 141 visit(node.elsePart); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 sb.add(' '); | 518 sb.add(' '); |
| 514 } | 519 } |
| 515 visit(node.name); | 520 visit(node.name); |
| 516 if (node.typeParameters !== null) { | 521 if (node.typeParameters !== null) { |
| 517 visit(node.typeParameters); | 522 visit(node.typeParameters); |
| 518 } | 523 } |
| 519 visit(node.formals); | 524 visit(node.formals); |
| 520 add(node.endToken.value); | 525 add(node.endToken.value); |
| 521 } | 526 } |
| 522 } | 527 } |
| OLD | NEW |