| 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 part of tree; | 5 part of tree; |
| 6 | 6 |
| 7 String unparse(Node node) { | 7 String unparse(Node node) { |
| 8 Unparser unparser = new Unparser(); | 8 Unparser unparser = new Unparser(); |
| 9 unparser.unparse(node); | 9 unparser.unparse(node); |
| 10 return unparser.result; | 10 return unparser.result; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 visit(node.conditionStatement); | 102 visit(node.conditionStatement); |
| 103 visit(node.update); | 103 visit(node.update); |
| 104 sb.add(')'); | 104 sb.add(')'); |
| 105 visit(node.body); | 105 visit(node.body); |
| 106 } | 106 } |
| 107 | 107 |
| 108 visitFunctionDeclaration(FunctionDeclaration node) { | 108 visitFunctionDeclaration(FunctionDeclaration node) { |
| 109 visit(node.function); | 109 visit(node.function); |
| 110 } | 110 } |
| 111 | 111 |
| 112 visitFunctionExpression(FunctionExpression node) { | 112 void unparseFunctionName(Node name) { |
| 113 // Check length to not print unnecessary whitespace. | |
| 114 if (node.modifiers.nodes.length() > 0) { | |
| 115 visit(node.modifiers); | |
| 116 sb.add(' '); | |
| 117 } | |
| 118 if (node.returnType != null) { | |
| 119 visit(node.returnType); | |
| 120 sb.add(' '); | |
| 121 } | |
| 122 if (node.getOrSet != null) { | |
| 123 add(node.getOrSet.value); | |
| 124 sb.add(' '); | |
| 125 } | |
| 126 // TODO(antonm): that's a workaround as currently FunctionExpression | 113 // TODO(antonm): that's a workaround as currently FunctionExpression |
| 127 // names are modelled with Send and it emits operator[] as only | 114 // names are modelled with Send and it emits operator[] as only |
| 128 // operator, without [] which are expected to be emitted with | 115 // operator, without [] which are expected to be emitted with |
| 129 // arguments. | 116 // arguments. |
| 130 if (node.name is Send) { | 117 if (name is Send) { |
| 131 Send send = node.name; | 118 Send send = name; |
| 132 assert(send is !SendSet); | 119 assert(send is !SendSet); |
| 133 if (!send.isOperator) { | 120 if (!send.isOperator) { |
| 134 // Looks like a factory method. | 121 // Looks like a factory method. |
| 135 visit(send.receiver); | 122 visit(send.receiver); |
| 136 sb.add('.'); | 123 sb.add('.'); |
| 137 } else { | 124 } else { |
| 138 visit(send.receiver); | 125 visit(send.receiver); |
| 139 Identifier identifier = send.selector.asIdentifier(); | 126 Identifier identifier = send.selector.asIdentifier(); |
| 140 if (identical(identifier.token.kind, KEYWORD_TOKEN)) { | 127 if (identical(identifier.token.kind, KEYWORD_TOKEN)) { |
| 141 sb.add(' '); | 128 sb.add(' '); |
| 142 } else if (identifier.source == const SourceString('negate')) { | 129 } else if (identifier.source == const SourceString('negate')) { |
| 143 // TODO(ahe): Remove special case for negate. | 130 // TODO(ahe): Remove special case for negate. |
| 144 sb.add(' '); | 131 sb.add(' '); |
| 145 } | 132 } |
| 146 } | 133 } |
| 147 visit(send.selector); | 134 visit(send.selector); |
| 148 } else { | 135 } else { |
| 149 visit(node.name); | 136 visit(name); |
| 150 } | 137 } |
| 138 } |
| 139 |
| 140 visitFunctionExpression(FunctionExpression node) { |
| 141 // Check length to not print unnecessary whitespace. |
| 142 if (node.modifiers.nodes.length() > 0) { |
| 143 visit(node.modifiers); |
| 144 sb.add(' '); |
| 145 } |
| 146 if (node.returnType != null) { |
| 147 visit(node.returnType); |
| 148 sb.add(' '); |
| 149 } |
| 150 if (node.getOrSet != null) { |
| 151 add(node.getOrSet.value); |
| 152 sb.add(' '); |
| 153 } |
| 154 unparseFunctionName(node.name); |
| 151 visit(node.parameters); | 155 visit(node.parameters); |
| 152 visit(node.initializers); | 156 visit(node.initializers); |
| 153 visit(node.body); | 157 visit(node.body); |
| 154 } | 158 } |
| 155 | 159 |
| 156 visitIdentifier(Identifier node) { | 160 visitIdentifier(Identifier node) { |
| 157 add(node.token.value); | 161 add(node.token.value); |
| 158 } | 162 } |
| 159 | 163 |
| 160 visitIf(If node) { | 164 visitIf(If node) { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 } | 597 } |
| 594 | 598 |
| 595 visitStatement(Statement node) { | 599 visitStatement(Statement node) { |
| 596 throw 'internal error'; // Should not be called. | 600 throw 'internal error'; // Should not be called. |
| 597 } | 601 } |
| 598 | 602 |
| 599 visitStringNode(StringNode node) { | 603 visitStringNode(StringNode node) { |
| 600 throw 'internal error'; // Should not be called. | 604 throw 'internal error'; // Should not be called. |
| 601 } | 605 } |
| 602 } | 606 } |
| OLD | NEW |