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

Unified Diff: frog/minfrog

Issue 9653021: Add support for implicitly concatenating adjacent string literals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added test case. 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 | « frog/gen.dart ('k') | frog/parser.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/minfrog
diff --git a/frog/minfrog b/frog/minfrog
index a1bb7ba34a4d32317b0933727b583424a94904a8..74f39e11f1d89829d28a30a40d52347aa62e4c3c 100755
--- a/frog/minfrog
+++ b/frog/minfrog
@@ -2651,6 +2651,10 @@ MethodAnalyzer.prototype.visitSuperExpression = function(node) {
MethodAnalyzer.prototype.visitLiteralExpression = function(node) {
return new PureStaticValue(node.value.get$type(), node.span, true, false);
}
+MethodAnalyzer.prototype.visitStringConcatExpression = function(node) {
+ node.strings.forEach(this.get$visitValue());
+ return this._frame._makeValue($globals.world.stringType, node);
+}
MethodAnalyzer.prototype.visitStringInterpExpression = function(node) {
node.pieces.forEach(this.get$visitValue());
return this._frame._makeValue($globals.world.stringType, node);
@@ -5136,6 +5140,16 @@ MethodGenerator.prototype._isUnaryIncrement = function(item) {
return false;
}
}
+MethodGenerator.prototype.visitStringConcatExpression = function(node) {
+ var items = [];
+ var $$list = node.strings;
+ for (var $$i = $$list.iterator(); $$i.hasNext(); ) {
+ var item = $$i.next();
+ var val = this.visitValue(item);
+ items.add(val.get$code());
+ }
+ return new Value($globals.world.stringType, ("(" + Strings.join(items, " + ") + ")"), node.span);
+}
MethodGenerator.prototype.visitStringInterpExpression = function(node) {
var items = [];
var $$list = node.pieces;
@@ -10172,13 +10186,9 @@ Parser.prototype.primary = function() {
return this._makeLiteral(Value.fromDouble(Math.parseDouble(t.get$text()), t.get$span()));
case (58):
-
- var t = this._lang_next();
- return this._makeLiteral(Value.fromString(t.get$value(), t.get$span()));
-
case (59):
- return this.stringInterpolation();
+ return this.adjacentStrings();
case (52):
@@ -10199,6 +10209,27 @@ Parser.prototype.primary = function() {
}
}
+Parser.prototype.adjacentStrings = function() {
+ var start = this._peekToken.start;
+ var strings = [];
+ while (this._peek() == (58) || this._peek() == (59)) {
+ var part = null;
+ if (this._peek() == (58)) {
+ var t = this._lang_next();
+ part = this._makeLiteral(Value.fromString(t.get$value(), t.get$span()));
+ }
+ else {
+ part = this.stringInterpolation();
+ }
+ strings.add(part);
+ }
+ if (strings.get$length() == (1)) {
+ return strings.$index((0));
+ }
+ else {
+ return new StringConcatExpression(strings, this._makeSpan(start));
+ }
+}
Parser.prototype.stringInterpolation = function() {
var start = this._peekToken.start;
var pieces = new Array();
@@ -11245,6 +11276,15 @@ LiteralExpression.prototype.set$value = function(value) { return this.value = va
LiteralExpression.prototype.visit = function(visitor) {
return visitor.visitLiteralExpression(this);
}
+// ********** Code for StringConcatExpression **************
+$inherits(StringConcatExpression, Expression);
+function StringConcatExpression(strings, span) {
+ this.strings = strings;
+ Expression.call(this, span);
+}
+StringConcatExpression.prototype.visit = function(visitor) {
+ return visitor.visitStringConcatExpression(this);
+}
// ********** Code for StringInterpExpression **************
$inherits(StringInterpExpression, Expression);
function StringInterpExpression(pieces, span) {
« no previous file with comments | « frog/gen.dart ('k') | frog/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698