Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Unified Diff: frog/gen.dart

Issue 8729018: Fixing string compile-time constant evaluation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: john comments Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « frog/frogsh ('k') | frog/member.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/gen.dart
diff --git a/frog/gen.dart b/frog/gen.dart
index c95a63686fe13adf57afcca1cd8737fd84aa0444..d18d7af6788017ab7269fe782585d1c6bd1c6db4 100644
--- a/frog/gen.dart
+++ b/frog/gen.dart
@@ -1756,12 +1756,26 @@ class MethodGenerator implements TreeVisitor {
var x = visitValue(node.x);
var y = visitValue(node.y);
if (x.isConst && y.isConst) {
- var value = kind == TokenKind.EQ_STRICT
- // Note: it is ok to use == and not === here since all of these
- // constant comparisons are applied to doubles, bool, or strings.
- // We need it for the compile-time evaluator because
- // (9).toDouble() === 9.0 is false in dartvm.
- ? x.actualValue == y.actualValue : x.actualValue != y.actualValue;
+ var xVal = x.actualValue;
+ var yVal = y.actualValue;
+
+ // cannonicalize strings if they are using different quote chars:
+ if (x.type.isString && y.type.isString
+ && xVal[0] != yVal[0]) {
+ if (xVal[0] == '"') {
+ xVal = xVal.substring(1, xVal.length - 1);
+ yVal = toDoubleQuote(yVal.substring(1, yVal.length - 1));
+ } else {
+ xVal = toDoubleQuote(xVal.substring(1, xVal.length - 1));
+ yVal = yVal.substring(1, yVal.length - 1);
+ }
+ }
+
+ // Note: it is ok to use == and not === here since all of these
+ // constant comparisons are applied to doubles, bool, or strings.
+ // We need it for the compile-time evaluator because
+ // (9).toDouble() === 9.0 is false in dartvm.
+ var value = kind == TokenKind.EQ_STRICT ? xVal == yVal : xVal != yVal;
return new EvaluatedValue(world.nonNullBool, value, "$value",
node.span);
}
@@ -2282,7 +2296,7 @@ class MethodGenerator implements TreeVisitor {
text = parseStringLiteral(text);
// TODO(jimhug): What about \r?
text = text.replaceAll('\n', '\\n');
- text = text.replaceAll('"', '\\"');
+ text = toDoubleQuote(text);
text = '"$text"';
}
if (text !== node.text) {
« no previous file with comments | « frog/frogsh ('k') | frog/member.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698