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

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: '' 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') | frog/member.dart » ('J')
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..64626c4817d5c202c80bde2cd6455dcf737f1f69 100644
--- a/frog/gen.dart
+++ b/frog/gen.dart
@@ -1756,12 +1756,27 @@ 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]) {
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.
+ 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);
+ }
+ }
+ 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.
+
+ // 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 +2297,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') | frog/member.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698