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 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]) { |
|
Jennifer Messerly
2011/11/29 18:55:48
does this need to handle multiline strings too?
Siggi Cherem (dart-lang)
2011/11/29 19:09:26
Thankfully no, we do normalize those.
| |
| 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 print("$xVal vs $yVal"); | |
|
Jennifer Messerly
2011/11/29 18:55:48
remove
Siggi Cherem (dart-lang)
2011/11/29 19:09:26
oops. thanks.
| |
| 1774 | |
| 1775 // Note: it is ok to use == and not === here since all of these | |
| 1776 // constant comparisons are applied to doubles, bool, or strings. | |
| 1777 // We need it for the compile-time evaluator because | |
| 1778 // (9).toDouble() === 9.0 is false in dartvm. | |
| 1779 var value = kind == TokenKind.EQ_STRICT ? xVal == yVal : xVal != yVal; | |
| 1765 return new EvaluatedValue(world.nonNullBool, value, "$value", | 1780 return new EvaluatedValue(world.nonNullBool, value, "$value", |
| 1766 node.span); | 1781 node.span); |
| 1767 } | 1782 } |
| 1768 if (x.code == 'null' || y.code == 'null') { | 1783 if (x.code == 'null' || y.code == 'null') { |
| 1769 // Switching to == ensures that null and undefined are interchangable. | 1784 // Switching to == ensures that null and undefined are interchangable. |
| 1770 final op = node.op.toString().substring(0,2); | 1785 final op = node.op.toString().substring(0,2); |
| 1771 return new Value(world.nonNullBool, '${x.code} $op ${y.code}', | 1786 return new Value(world.nonNullBool, '${x.code} $op ${y.code}', |
| 1772 node.span); | 1787 node.span); |
| 1773 } else { | 1788 } else { |
| 1774 // TODO(jimhug): Resolve issue with undefined and null here. | 1789 // 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 | 2290 // TODO(jimhug): Confirm that only strings need possible translation |
| 2276 if (type.isString) { | 2291 if (type.isString) { |
| 2277 if (text.startsWith('@')) { | 2292 if (text.startsWith('@')) { |
| 2278 text = _escapeString(parseStringLiteral(text)); | 2293 text = _escapeString(parseStringLiteral(text)); |
| 2279 text = '"$text"'; | 2294 text = '"$text"'; |
| 2280 } else if (isMultilineString(text)) { | 2295 } else if (isMultilineString(text)) { |
| 2281 // convert multi-line strings into single-line | 2296 // convert multi-line strings into single-line |
| 2282 text = parseStringLiteral(text); | 2297 text = parseStringLiteral(text); |
| 2283 // TODO(jimhug): What about \r? | 2298 // TODO(jimhug): What about \r? |
| 2284 text = text.replaceAll('\n', '\\n'); | 2299 text = text.replaceAll('\n', '\\n'); |
| 2285 text = text.replaceAll('"', '\\"'); | 2300 text = toDoubleQuote(text); |
| 2286 text = '"$text"'; | 2301 text = '"$text"'; |
| 2287 } | 2302 } |
| 2288 if (text !== node.text) { | 2303 if (text !== node.text) { |
| 2289 node.value = text; | 2304 node.value = text; |
| 2290 node.text = text; | 2305 node.text = text; |
| 2291 } | 2306 } |
| 2292 } | 2307 } |
| 2293 | 2308 |
| 2294 // TODO(jimhug): Should pass node.span - but that breaks something... | 2309 // TODO(jimhug): Should pass node.span - but that breaks something... |
| 2295 return new EvaluatedValue(type, node.value, node.text, null); | 2310 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)); | 2424 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); |
| 2410 } | 2425 } |
| 2411 for (int i = bareCount; i < length; i++) { | 2426 for (int i = bareCount; i < length; i++) { |
| 2412 var name = getName(i); | 2427 var name = getName(i); |
| 2413 if (name == null) name = '\$$i'; | 2428 if (name == null) name = '\$$i'; |
| 2414 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); | 2429 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); |
| 2415 } | 2430 } |
| 2416 return new Arguments(nodes, result); | 2431 return new Arguments(nodes, result); |
| 2417 } | 2432 } |
| 2418 } | 2433 } |
| OLD | NEW |