Chromium Code Reviews| 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 2129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2140 // If the user calls "new Interface()" we want the result type to be the | 2140 // If the user calls "new Interface()" we want the result type to be the |
| 2141 // interface, not the class. | 2141 // interface, not the class. |
| 2142 var target = new Value.type(type, typeRef.span); | 2142 var target = new Value.type(type, typeRef.span); |
| 2143 return m.invoke(this, node, target, _makeArgs(node.arguments)); | 2143 return m.invoke(this, node, target, _makeArgs(node.arguments)); |
| 2144 } | 2144 } |
| 2145 | 2145 |
| 2146 visitListExpression(ListExpression node) { | 2146 visitListExpression(ListExpression node) { |
| 2147 // TODO(jimhug): Use node.type or other type inference here. | 2147 // TODO(jimhug): Use node.type or other type inference here. |
| 2148 var argsCode = []; | 2148 var argsCode = []; |
| 2149 var argValues = []; | 2149 var argValues = []; |
| 2150 var type = null; | |
| 2151 if (node.type !== null) { | |
| 2152 // The parser makes node.type a list type, we extract its type argument. | |
| 2153 type = method.resolveType(node.type, true).typeArgsInOrder[0]; | |
| 2154 if (node.isConst && (type is ParameterType || type.hasTypeParams)) { | |
| 2155 world.error('type parameter cannot be used in const list literals'); | |
| 2156 } | |
| 2157 } | |
| 2150 for (var item in node.values) { | 2158 for (var item in node.values) { |
| 2151 var arg = visitValue(item); | 2159 var arg = type === null ? visitValue(item) : visitTypedValue(item, type); |
|
Jennifer Messerly
2011/12/08 02:13:26
I'd move this check into visitTypedValue. Especial
Siggi Cherem (dart-lang)
2011/12/08 23:02:15
Done
| |
| 2152 argValues.add(arg); | 2160 argValues.add(arg); |
| 2153 if (node.isConst) { | 2161 if (node.isConst) { |
| 2154 if (!arg.isConst) { | 2162 if (!arg.isConst) { |
| 2155 world.error('const list can only contain const values', item.span); | 2163 world.error('const list can only contain const values', item.span); |
| 2156 argsCode.add(arg.code); | 2164 argsCode.add(arg.code); |
| 2157 } else { | 2165 } else { |
| 2158 argsCode.add(arg.canonicalCode); | 2166 argsCode.add(arg.canonicalCode); |
| 2159 } | 2167 } |
| 2160 } else { | 2168 } else { |
| 2161 argsCode.add(arg.code); | 2169 argsCode.add(arg.code); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2182 | 2190 |
| 2183 visitMapExpression(MapExpression node) { | 2191 visitMapExpression(MapExpression node) { |
| 2184 // Special case the empty non-const map. | 2192 // Special case the empty non-const map. |
| 2185 if (node.items.length == 0 && !node.isConst) { | 2193 if (node.items.length == 0 && !node.isConst) { |
| 2186 return world.mapType.getConstructor('').invoke(this, node, | 2194 return world.mapType.getConstructor('').invoke(this, node, |
| 2187 new Value.type(world.mapType, node.span), Arguments.EMPTY); | 2195 new Value.type(world.mapType, node.span), Arguments.EMPTY); |
| 2188 } | 2196 } |
| 2189 | 2197 |
| 2190 var argValues = []; | 2198 var argValues = []; |
| 2191 var argsCode = []; | 2199 var argsCode = []; |
| 2200 var type = null; | |
| 2201 if (node.type !== null) { | |
| 2202 // node.type is a map type, extract the type argument for the values. | |
| 2203 type = method.resolveType(node.type, true).typeArgsInOrder[1]; | |
| 2204 if (node.isConst && (type is ParameterType || type.hasTypeParams)) { | |
| 2205 world.error('type parameter cannot be used in const map literals'); | |
| 2206 } | |
| 2207 } | |
| 2192 for (int i = 0; i < node.items.length; i += 2) { | 2208 for (int i = 0; i < node.items.length; i += 2) { |
| 2193 // TODO(jimhug): Use node.type or other type inference here. | 2209 // TODO(jimhug): Use node.type or other type inference here. |
| 2194 // TODO(jimhug): Would be nice to allow arbitrary keys here. | 2210 // TODO(jimhug): Would be nice to allow arbitrary keys here (this is |
| 2211 // currently not allowed by the spec). | |
| 2195 var key = visitTypedValue(node.items[i], world.stringType); | 2212 var key = visitTypedValue(node.items[i], world.stringType); |
| 2196 final valueItem = node.items[i+1]; | 2213 final valueItem = node.items[i+1]; |
| 2197 var value = visitValue(valueItem); | 2214 var value = type === null ? visitValue(valueItem) |
| 2215 : visitTypedValue(valueItem, type); | |
| 2198 argValues.add(key); | 2216 argValues.add(key); |
| 2199 argValues.add(value); | 2217 argValues.add(value); |
| 2200 | 2218 |
| 2201 if (node.isConst) { | 2219 if (node.isConst) { |
| 2202 if (!key.isConst || !value.isConst) { | 2220 if (!key.isConst || !value.isConst) { |
| 2203 world.error('const map can only contain const values', | 2221 world.error('const map can only contain const values', |
| 2204 valueItem.span); | 2222 valueItem.span); |
| 2205 argsCode.add(key.code); | 2223 argsCode.add(key.code); |
| 2206 argsCode.add(value.code); | 2224 argsCode.add(value.code); |
| 2207 } else { | 2225 } else { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2468 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); | 2486 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); |
| 2469 } | 2487 } |
| 2470 for (int i = bareCount; i < length; i++) { | 2488 for (int i = bareCount; i < length; i++) { |
| 2471 var name = getName(i); | 2489 var name = getName(i); |
| 2472 if (name == null) name = '\$$i'; | 2490 if (name == null) name = '\$$i'; |
| 2473 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); | 2491 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); |
| 2474 } | 2492 } |
| 2475 return new Arguments(nodes, result); | 2493 return new Arguments(nodes, result); |
| 2476 } | 2494 } |
| 2477 } | 2495 } |
| OLD | NEW |