| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * Top level generator object for writing code and keeping track of | 6 * Top level generator object for writing code and keeping track of |
| 7 * dependencies. | 7 * dependencies. |
| 8 * | 8 * |
| 9 * Should have two compilation models, but only one implemented so far. | 9 * Should have two compilation models, but only one implemented so far. |
| 10 * | 10 * |
| (...skipping 2095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2106 visitSuperExpression(SuperExpression node) { | 2106 visitSuperExpression(SuperExpression node) { |
| 2107 return _makeSuperValue(node); | 2107 return _makeSuperValue(node); |
| 2108 } | 2108 } |
| 2109 | 2109 |
| 2110 visitNullExpression(NullExpression node) { | 2110 visitNullExpression(NullExpression node) { |
| 2111 // TODO(jimhug): should be passing node.span | 2111 // TODO(jimhug): should be passing node.span |
| 2112 // TODO(jimhug): Can we do better than var for the type? | 2112 // TODO(jimhug): Can we do better than var for the type? |
| 2113 return new EvaluatedValue(world.varType, null, 'null', null); | 2113 return new EvaluatedValue(world.varType, null, 'null', null); |
| 2114 } | 2114 } |
| 2115 | 2115 |
| 2116 _isUnaryIncrement(Expression item) { |
| 2117 if (item is UnaryExpression) { |
| 2118 UnaryExpression u = item; |
| 2119 return u.op.kind == TokenKind.INCR || u.op.kind == TokenKind.DECR; |
| 2120 } else { |
| 2121 return false; |
| 2122 } |
| 2123 } |
| 2124 |
| 2116 visitLiteralExpression(LiteralExpression node) { | 2125 visitLiteralExpression(LiteralExpression node) { |
| 2117 // All Literal types are filled in at parse time, so no need to resolve. | 2126 // All Literal types are filled in at parse time, so no need to resolve. |
| 2118 var type = node.type.type; | 2127 var type = node.type.type; |
| 2119 assert(type != null); | 2128 assert(type != null); |
| 2120 | 2129 |
| 2121 if (node.value is List) { | 2130 if (node.value is List) { |
| 2122 var items = []; | 2131 var items = []; |
| 2123 for (var item in node.value) { | 2132 for (var item in node.value) { |
| 2124 var val = visitValue(item); | 2133 var val = visitValue(item); |
| 2125 val.invoke(this, 'toString', item, Arguments.EMPTY); | 2134 val.invoke(this, 'toString', item, Arguments.EMPTY); |
| 2126 | 2135 |
| 2127 // TODO(jimhug): Ensure this solves all precedence problems. | 2136 // TODO(jimhug): Ensure this solves all precedence problems. |
| 2137 // TODO(jmesserly): We could be smarter about prefix/postfix, but we'd |
| 2138 // need to know if it will compile to a ++ or to some sort of += form. |
| 2128 var code = val.code; | 2139 var code = val.code; |
| 2129 if (item is BinaryExpression || item is ConditionalExpression) { | 2140 if (item is BinaryExpression || item is ConditionalExpression |
| 2141 || item is PostfixExpression || _isUnaryIncrement(item)) { |
| 2130 code = '(${code})'; | 2142 code = '(${code})'; |
| 2131 } | 2143 } |
| 2132 items.add(code); | 2144 items.add(code); |
| 2133 } | 2145 } |
| 2134 return new Value(type, '(${Strings.join(items, " + ")})', node.span); | 2146 return new Value(type, '(${Strings.join(items, " + ")})', node.span); |
| 2135 } | 2147 } |
| 2136 | 2148 |
| 2137 var text = node.text; | 2149 var text = node.text; |
| 2138 // TODO(jimhug): Confirm that only strings need possible translation | 2150 // TODO(jimhug): Confirm that only strings need possible translation |
| 2139 if (type.isString) { | 2151 if (type.isString) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2272 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); | 2284 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); |
| 2273 } | 2285 } |
| 2274 for (int i = bareCount; i < length; i++) { | 2286 for (int i = bareCount; i < length; i++) { |
| 2275 var name = getName(i); | 2287 var name = getName(i); |
| 2276 if (name == null) name = '\$$i'; | 2288 if (name == null) name = '\$$i'; |
| 2277 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); | 2289 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); |
| 2278 } | 2290 } |
| 2279 return new Arguments(nodes, result); | 2291 return new Arguments(nodes, result); |
| 2280 } | 2292 } |
| 2281 } | 2293 } |
| OLD | NEW |