| 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 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1749 var value = (kind == TokenKind.AND) | 1749 var value = (kind == TokenKind.AND) |
| 1750 ? x.actualValue && y.actualValue : x.actualValue || y.actualValue; | 1750 ? x.actualValue && y.actualValue : x.actualValue || y.actualValue; |
| 1751 return new EvaluatedValue(world.nonNullBool, value, '$value', | 1751 return new EvaluatedValue(world.nonNullBool, value, '$value', |
| 1752 node.span); | 1752 node.span); |
| 1753 } | 1753 } |
| 1754 return new Value(world.nonNullBool, code, node.span); | 1754 return new Value(world.nonNullBool, code, node.span); |
| 1755 } else if (kind == TokenKind.EQ_STRICT || kind == TokenKind.NE_STRICT) { | 1755 } else if (kind == TokenKind.EQ_STRICT || kind == TokenKind.NE_STRICT) { |
| 1756 var x = visitValue(node.x); | 1756 var x = visitValue(node.x); |
| 1757 var y = visitValue(node.y); | 1757 var y = visitValue(node.y); |
| 1758 if (x.isConst && y.isConst) { | 1758 if (x.isConst && y.isConst) { |
| 1759 var value = kind == TokenKind.EQ_STRICT | 1759 var xVal = x.actualValue; |
| 1760 // Note: it is ok to use == and not === here since all of these | 1760 var yVal = y.actualValue; |
| 1761 // constant comparisons are applied to doubles, bool, or strings. | 1761 |
| 1762 // We need it for the compile-time evaluator because | 1762 // cannonicalize strings if they are using different quote chars: |
| 1763 // (9).toDouble() === 9.0 is false in dartvm. | 1763 if (x.type.isString && y.type.isString |
| 1764 ? x.actualValue == y.actualValue : x.actualValue != y.actualValue; | 1764 && xVal[0] != yVal[0]) { |
| 1765 if (xVal[0] == '"') { |
| 1766 xVal = xVal.substring(1, xVal.length - 1); |
| 1767 yVal = toDoubleQuote(yVal.substring(1, yVal.length - 1)); |
| 1768 } else { |
| 1769 xVal = toDoubleQuote(xVal.substring(1, xVal.length - 1)); |
| 1770 yVal = yVal.substring(1, yVal.length - 1); |
| 1771 } |
| 1772 } |
| 1773 |
| 1774 // Note: it is ok to use == and not === here since all of these |
| 1775 // constant comparisons are applied to doubles, bool, or strings. |
| 1776 // We need it for the compile-time evaluator because |
| 1777 // (9).toDouble() === 9.0 is false in dartvm. |
| 1778 var value = kind == TokenKind.EQ_STRICT ? xVal == yVal : xVal != yVal; |
| 1765 return new EvaluatedValue(world.nonNullBool, value, "$value", | 1779 return new EvaluatedValue(world.nonNullBool, value, "$value", |
| 1766 node.span); | 1780 node.span); |
| 1767 } | 1781 } |
| 1768 if (x.code == 'null' || y.code == 'null') { | 1782 if (x.code == 'null' || y.code == 'null') { |
| 1769 // Switching to == ensures that null and undefined are interchangable. | 1783 // Switching to == ensures that null and undefined are interchangable. |
| 1770 final op = node.op.toString().substring(0,2); | 1784 final op = node.op.toString().substring(0,2); |
| 1771 return new Value(world.nonNullBool, '${x.code} $op ${y.code}', | 1785 return new Value(world.nonNullBool, '${x.code} $op ${y.code}', |
| 1772 node.span); | 1786 node.span); |
| 1773 } else { | 1787 } else { |
| 1774 // TODO(jimhug): Resolve issue with undefined and null here. | 1788 // TODO(jimhug): Resolve issue with undefined and null here. |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2275 // TODO(jimhug): Confirm that only strings need possible translation | 2289 // TODO(jimhug): Confirm that only strings need possible translation |
| 2276 if (type.isString) { | 2290 if (type.isString) { |
| 2277 if (text.startsWith('@')) { | 2291 if (text.startsWith('@')) { |
| 2278 text = _escapeString(parseStringLiteral(text)); | 2292 text = _escapeString(parseStringLiteral(text)); |
| 2279 text = '"$text"'; | 2293 text = '"$text"'; |
| 2280 } else if (isMultilineString(text)) { | 2294 } else if (isMultilineString(text)) { |
| 2281 // convert multi-line strings into single-line | 2295 // convert multi-line strings into single-line |
| 2282 text = parseStringLiteral(text); | 2296 text = parseStringLiteral(text); |
| 2283 // TODO(jimhug): What about \r? | 2297 // TODO(jimhug): What about \r? |
| 2284 text = text.replaceAll('\n', '\\n'); | 2298 text = text.replaceAll('\n', '\\n'); |
| 2285 text = text.replaceAll('"', '\\"'); | 2299 text = toDoubleQuote(text); |
| 2286 text = '"$text"'; | 2300 text = '"$text"'; |
| 2287 } | 2301 } |
| 2288 if (text !== node.text) { | 2302 if (text !== node.text) { |
| 2289 node.value = text; | 2303 node.value = text; |
| 2290 node.text = text; | 2304 node.text = text; |
| 2291 } | 2305 } |
| 2292 } | 2306 } |
| 2293 | 2307 |
| 2294 // TODO(jimhug): Should pass node.span - but that breaks something... | 2308 // TODO(jimhug): Should pass node.span - but that breaks something... |
| 2295 return new EvaluatedValue(type, node.value, node.text, null); | 2309 return new EvaluatedValue(type, node.value, node.text, null); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2409 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); | 2423 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); |
| 2410 } | 2424 } |
| 2411 for (int i = bareCount; i < length; i++) { | 2425 for (int i = bareCount; i < length; i++) { |
| 2412 var name = getName(i); | 2426 var name = getName(i); |
| 2413 if (name == null) name = '\$$i'; | 2427 if (name == null) name = '\$$i'; |
| 2414 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); | 2428 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); |
| 2415 } | 2429 } |
| 2416 return new Arguments(nodes, result); | 2430 return new Arguments(nodes, result); |
| 2417 } | 2431 } |
| 2418 } | 2432 } |
| OLD | NEW |