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

Side by Side Diff: frog/member.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 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /** A formal parameter to a [Method]. */ 5 /** A formal parameter to a [Method]. */
6 class Parameter { 6 class Parameter {
7 FormalNode definition; 7 FormalNode definition;
8 Member method; 8 Member method;
9 9
10 String name; 10 String name;
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 } 1170 }
1171 } else if (declaringType.isString) { 1171 } else if (declaringType.isString) {
1172 if (name == '\$index') { 1172 if (name == '\$index') {
1173 // Note: this could technically propagate constness, but that's not 1173 // Note: this could technically propagate constness, but that's not
1174 // specified explicitly and the VM doesn't do that. 1174 // specified explicitly and the VM doesn't do that.
1175 return new Value(declaringType, '${target.code}[${argsCode[0]}]', 1175 return new Value(declaringType, '${target.code}[${argsCode[0]}]',
1176 node.span); 1176 node.span);
1177 } else if (name == '\$add') { 1177 } else if (name == '\$add') {
1178 if (allConst) { 1178 if (allConst) {
1179 var val0 = target.dynamic.actualValue; 1179 var val0 = target.dynamic.actualValue;
1180 var quote0 = val0[0];
1180 val0 = val0.substring(1, val0.length - 1); 1181 val0 = val0.substring(1, val0.length - 1);
1181 var val1 = args.values[0].dynamic.actualValue; 1182 var val1 = args.values[0].dynamic.actualValue;
1183 var quote1 = null;
1182 if (args.values[0].type.isString) { 1184 if (args.values[0].type.isString) {
1185 quote1 = val1[0];
1183 val1 = val1.substring(1, val1.length - 1); 1186 val1 = val1.substring(1, val1.length - 1);
1184 } 1187 }
1185 var value = '${val0}${val1}'; 1188 // ensure that both strings use the same quote char:
Jennifer Messerly 2011/11/29 18:55:48 it'd be really nice if this was pulled out into it
Siggi Cherem (dart-lang) 2011/11/29 19:09:26 Done.
1186 value = '"' + value.replaceAll('"', '\\"') + '"'; 1189 var value;
1190 if (quote0 == quote1 || quote1 == null) {
1191 // if both strings use the same quote, then merge them together
1192 value = '$quote0${val0}${val1}$quote0';
1193 } else if (quote0 == '"') {
1194 // if they are different, escape the single-quote to be double-quote
1195 // the choice of single vs double is arbitrary, but choosing one
1196 // ensures that we only do this escaping once on a string portion.
1197 assert(quote1 == "'");
1198 value = '$quote0${val0}${toDoubleQuote(val1)}$quote0';
1199 } else {
1200 assert(quote1 == '"');
1201 value = '$quote1${toDoubleQuote(val0)}${val1}$quote1';
1202 }
1187 return new EvaluatedValue(world.stringType, value, value, node.span); 1203 return new EvaluatedValue(world.stringType, value, value, node.span);
1188 } 1204 }
1189 1205
1190 // Ensure we generate toString on the right side 1206 // Ensure we generate toString on the right side
1191 return new Value(declaringType, '${target.code} + ${argsCode[0]}', 1207 return new Value(declaringType, '${target.code} + ${argsCode[0]}',
1192 node.span); 1208 node.span);
1193 } 1209 }
1194 } else if (declaringType.isNative) { 1210 } else if (declaringType.isNative) {
1195 if (name == '\$index') { 1211 if (name == '\$index') {
1196 // Note: this could technically propagate constness, but that's not 1212 // Note: this could technically propagate constness, but that's not
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 } 1674 }
1659 1675
1660 void forEach(void f(Member member)) { 1676 void forEach(void f(Member member)) {
1661 factories.forEach((_, Map constructors) { 1677 factories.forEach((_, Map constructors) {
1662 constructors.forEach((_, Member member) { 1678 constructors.forEach((_, Member member) {
1663 f(member); 1679 f(member);
1664 }); 1680 });
1665 }); 1681 });
1666 } 1682 }
1667 } 1683 }
OLDNEW
« frog/gen.dart ('K') | « frog/gen.dart ('k') | frog/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698