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

Unified Diff: frog/leg/compile_time_constants.dart

Issue 9706018: Make string interpolations be compile-time-constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/compile_time_constants.dart
diff --git a/frog/leg/compile_time_constants.dart b/frog/leg/compile_time_constants.dart
index cefe2f5f2a70f8d0f44862a181f09597555c33cf..053a79affc00f9ce31880b09bb4337a733f7f89e 100644
--- a/frog/leg/compile_time_constants.dart
+++ b/frog/leg/compile_time_constants.dart
@@ -333,9 +333,9 @@ class MapConstant extends ObjectConstant {
buffer.add("$isolatePrototype.$name");
} else {
value.writeJsCode(buffer, handler);
- }
+ }
}
- buffer.add("}");
+ buffer.add("}");
}
void badFieldCountError() {
@@ -768,6 +768,36 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
return new StringConstant(node.dartString);
}
+ Constant visitStringJuxtapostion(StringJuxtaposition node) {
+ if (node.dartString !== null) {
ngeoffray 2012/03/15 08:09:41 !node.isInterpolation
Lasse Reichstein Nielsen 2012/03/15 08:39:09 For consistency :)
+ return new StringConstant(node.dartString);
+ }
+ StringConstant left = evaluate(node.left);
+ StringConstant right = evaluate(node.right);
+ return new StringConstant(new DartString.concat(left.value, right.value));
+ }
+
+ Constant visitStringInterpolation(StringInterpolation node) {
+ StringConstant initialString = evaluate(node.string);
+ DartString accumulator = initialString.value;
+ for (StringInterpolationPart part in node.parts) {
+ Constant expression = evaluate(part.expression);
+ DartString expressionString;
+ if (expression.isNum() || expression.isBool()) {
+ Object value = expression.value;
+ expressionString = new DartString.literal(value.toString());
+ } else if (expression.isString()) {
+ expressionString = expression.value;
+ } else {
+ error(part.expression);
+ }
+ accumulator = new DartString.concat(accumulator, expressionString);
+ StringConstant partString = evaluate(part.string);
+ accumulator = new DartString.concat(accumulator, partString.value);
+ };
ngeoffray 2012/03/15 08:09:41 extra ';'
Lasse Reichstein Nielsen 2012/03/15 08:39:09 well spotted.
+ return new StringConstant(accumulator);
+ }
+
// TODO(floitsch): provide better error-messages.
Constant visitSend(Send send) {
Element element = elements[send];
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698