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

Side by Side Diff: pkg/compiler/lib/src/constants/expressions.dart

Issue 1166723002: Add StringLengthConstantExpression (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update .fromEnvironment test expectations. Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library dart2js.constants.expressions; 5 library dart2js.constants.expressions;
6 6
7 import '../constants/constant_system.dart'; 7 import '../constants/constant_system.dart';
8 import '../dart2jslib.dart' show assertDebugMode, Compiler; 8 import '../dart2jslib.dart' show assertDebugMode, Compiler;
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../elements/elements.dart' show 10 import '../elements/elements.dart' show
(...skipping 20 matching lines...) Expand all
31 ERRONEOUS, 31 ERRONEOUS,
32 FUNCTION, 32 FUNCTION,
33 IDENTICAL, 33 IDENTICAL,
34 INT, 34 INT,
35 INT_FROM_ENVIRONMENT, 35 INT_FROM_ENVIRONMENT,
36 LIST, 36 LIST,
37 MAP, 37 MAP,
38 NULL, 38 NULL,
39 STRING, 39 STRING,
40 STRING_FROM_ENVIRONMENT, 40 STRING_FROM_ENVIRONMENT,
41 STRING_LENGTH,
41 SYMBOL, 42 SYMBOL,
42 TYPE, 43 TYPE,
43 UNARY, 44 UNARY,
44 VARIABLE, 45 VARIABLE,
45 46
46 POSITIONAL_REFERENCE, 47 POSITIONAL_REFERENCE,
47 NAMED_REFERENCE, 48 NAMED_REFERENCE,
48 } 49 }
49 50
50 /// Environment used for evaluating constant expressions. 51 /// Environment used for evaluating constant expressions.
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 expression == other.expression; 996 expression == other.expression;
996 } 997 }
997 998
998 static const Map<UnaryOperatorKind, int> PRECEDENCE_MAP = const { 999 static const Map<UnaryOperatorKind, int> PRECEDENCE_MAP = const {
999 UnaryOperatorKind.NOT: 14, 1000 UnaryOperatorKind.NOT: 14,
1000 UnaryOperatorKind.COMPLEMENT: 14, 1001 UnaryOperatorKind.COMPLEMENT: 14,
1001 UnaryOperatorKind.NEGATE: 14, 1002 UnaryOperatorKind.NEGATE: 14,
1002 }; 1003 };
1003 } 1004 }
1004 1005
1006
1007 /// A string length constant expression like `a.length`.
1008 class StringLengthConstantExpression extends ConstantExpression {
1009 final ConstantValue value;
1010 final ConstantExpression expression;
1011
1012 StringLengthConstantExpression(this.value, this.expression);
1013
1014 ConstantExpressionKind get kind => ConstantExpressionKind.STRING_LENGTH;
1015
1016 accept(ConstantExpressionVisitor visitor, [context]) {
1017 return visitor.visitStringLength(this, context);
1018 }
1019
1020 @override
1021 ConstantValue evaluate(Environment environment,
1022 ConstantSystem constantSystem) {
1023 ConstantValue value = expression.evaluate(environment, constantSystem);
1024 if (value.isString) {
1025 StringConstantValue stringValue = value;
1026 return constantSystem.createInt(stringValue.primitiveValue.length);
1027 }
1028 return new NonConstantValue();
1029 }
1030
1031 ConstantExpression apply(NormalizedArguments arguments) {
1032 return new StringLengthConstantExpression(
1033 value,
1034 expression.apply(arguments));
1035 }
1036
1037 int get precedence => 15;
1038
1039 @override
1040 int _computeHashCode() {
1041 return 23 * expression.hashCode;
1042 }
1043
1044 @override
1045 bool _equals(StringLengthConstantExpression other) {
1046 return expression == other.expression;
1047 }
1048 }
1049
1005 /// A constant conditional expression like `a ? b : c`. 1050 /// A constant conditional expression like `a ? b : c`.
1006 class ConditionalConstantExpression extends ConstantExpression { 1051 class ConditionalConstantExpression extends ConstantExpression {
1007 final ConstantValue value; 1052 final ConstantValue value;
1008 final ConstantExpression condition; 1053 final ConstantExpression condition;
1009 final ConstantExpression trueExp; 1054 final ConstantExpression trueExp;
1010 final ConstantExpression falseExp; 1055 final ConstantExpression falseExp;
1011 1056
1012 ConditionalConstantExpression(this.value, 1057 ConditionalConstantExpression(this.value,
1013 this.condition, 1058 this.condition,
1014 this.trueExp, 1059 this.trueExp,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 1173
1129 @override 1174 @override
1130 ConstantValue evaluate(Environment environment, 1175 ConstantValue evaluate(Environment environment,
1131 ConstantSystem constantSystem) { 1176 ConstantSystem constantSystem) {
1132 throw new UnsupportedError('NamedArgumentReference.evaluate'); 1177 throw new UnsupportedError('NamedArgumentReference.evaluate');
1133 } 1178 }
1134 } 1179 }
1135 1180
1136 abstract class FromEnvironmentConstantExpression extends ConstantExpression { 1181 abstract class FromEnvironmentConstantExpression extends ConstantExpression {
1137 final ConstantValue value; 1182 final ConstantValue value;
1138 final String name; 1183 final ConstantExpression name;
1139 final ConstantExpression defaultValue; 1184 final ConstantExpression defaultValue;
1140 1185
1141 FromEnvironmentConstantExpression(this.value, this.name, this.defaultValue); 1186 FromEnvironmentConstantExpression(this.value, this.name, this.defaultValue);
1142 1187
1143 @override 1188 @override
1144 int _computeHashCode() { 1189 int _computeHashCode() {
1145 return 13 * name.hashCode + 1190 return 13 * name.hashCode +
1146 17 * defaultValue.hashCode; 1191 17 * defaultValue.hashCode;
1147 } 1192 }
1148 1193
1149 @override 1194 @override
1150 bool _equals(FromEnvironmentConstantExpression other) { 1195 bool _equals(FromEnvironmentConstantExpression other) {
1151 return name == other.name && 1196 return name == other.name &&
1152 defaultValue == other.defaultValue; 1197 defaultValue == other.defaultValue;
1153 } 1198 }
1154 } 1199 }
1155 1200
1156 /// A `const bool.fromEnvironment` constant. 1201 /// A `const bool.fromEnvironment` constant.
1157 class BoolFromEnvironmentConstantExpression 1202 class BoolFromEnvironmentConstantExpression
1158 extends FromEnvironmentConstantExpression { 1203 extends FromEnvironmentConstantExpression {
1159 1204
1160 BoolFromEnvironmentConstantExpression( 1205 BoolFromEnvironmentConstantExpression(
1161 ConstantValue value, 1206 ConstantValue value,
1162 String name, 1207 ConstantExpression name,
1163 ConstantExpression defaultValue) 1208 ConstantExpression defaultValue)
1164 : super(value, name, defaultValue); 1209 : super(value, name, defaultValue);
1165 1210
1166 ConstantExpressionKind get kind { 1211 ConstantExpressionKind get kind {
1167 return ConstantExpressionKind.BOOL_FROM_ENVIRONMENT; 1212 return ConstantExpressionKind.BOOL_FROM_ENVIRONMENT;
1168 } 1213 }
1169 1214
1170 accept(ConstantExpressionVisitor visitor, [context]) { 1215 accept(ConstantExpressionVisitor visitor, [context]) {
1171 return visitor.visitBoolFromEnvironment(this, context); 1216 return visitor.visitBoolFromEnvironment(this, context);
1172 } 1217 }
1173 1218
1174 @override 1219 @override
1175 ConstantValue evaluate(Environment environment, 1220 ConstantValue evaluate(Environment environment,
1176 ConstantSystem constantSystem) { 1221 ConstantSystem constantSystem) {
1177 String text = environment.readFromEnvironment(name); 1222 ConstantValue nameConstantValue =
1223 name.evaluate(environment, constantSystem);
1224 ConstantValue defaultConstantValue;
1225 if (defaultValue != null) {
1226 defaultConstantValue =
1227 defaultValue.evaluate(environment, constantSystem);
1228 } else {
1229 defaultConstantValue = constantSystem.createBool(false);
1230 }
1231 if (!nameConstantValue.isString) {
1232 return new NonConstantValue();
1233 }
1234 StringConstantValue nameStringConstantValue = nameConstantValue;
1235 String text = environment.readFromEnvironment(
1236 nameStringConstantValue.primitiveValue.slowToString());
1178 if (text == 'true') { 1237 if (text == 'true') {
1179 return constantSystem.createBool(true); 1238 return constantSystem.createBool(true);
1180 } else if (text == 'false') { 1239 } else if (text == 'false') {
1181 return constantSystem.createBool(false); 1240 return constantSystem.createBool(false);
1182 } else { 1241 } else {
1183 return defaultValue.evaluate(environment, constantSystem); 1242 return defaultConstantValue;
1184 } 1243 }
1185 } 1244 }
1186 1245
1187 ConstantExpression apply(NormalizedArguments arguments) { 1246 ConstantExpression apply(NormalizedArguments arguments) {
1188 return new BoolFromEnvironmentConstantExpression( 1247 return new BoolFromEnvironmentConstantExpression(
1189 null, name, defaultValue.apply(arguments)); 1248 null,
1249 name.apply(arguments),
1250 defaultValue != null ? defaultValue.apply(arguments) : null);
1190 } 1251 }
1191 } 1252 }
1192 1253
1193 /// A `const int.fromEnvironment` constant. 1254 /// A `const int.fromEnvironment` constant.
1194 class IntFromEnvironmentConstantExpression 1255 class IntFromEnvironmentConstantExpression
1195 extends FromEnvironmentConstantExpression { 1256 extends FromEnvironmentConstantExpression {
1196 1257
1197 IntFromEnvironmentConstantExpression( 1258 IntFromEnvironmentConstantExpression(
1198 ConstantValue value, 1259 ConstantValue value,
1199 String name, 1260 ConstantExpression name,
1200 ConstantExpression defaultValue) 1261 ConstantExpression defaultValue)
1201 : super(value, name, defaultValue); 1262 : super(value, name, defaultValue);
1202 1263
1203 ConstantExpressionKind get kind { 1264 ConstantExpressionKind get kind {
1204 return ConstantExpressionKind.INT_FROM_ENVIRONMENT; 1265 return ConstantExpressionKind.INT_FROM_ENVIRONMENT;
1205 } 1266 }
1206 1267
1207 accept(ConstantExpressionVisitor visitor, [context]) { 1268 accept(ConstantExpressionVisitor visitor, [context]) {
1208 return visitor.visitIntFromEnvironment(this, context); 1269 return visitor.visitIntFromEnvironment(this, context);
1209 } 1270 }
1210 1271
1211 @override 1272 @override
1212 ConstantValue evaluate(Environment environment, 1273 ConstantValue evaluate(Environment environment,
1213 ConstantSystem constantSystem) { 1274 ConstantSystem constantSystem) {
1275 ConstantValue nameConstantValue =
1276 name.evaluate(environment, constantSystem);
1277 ConstantValue defaultConstantValue;
1278 if (defaultValue != null) {
1279 defaultConstantValue =
1280 defaultValue.evaluate(environment, constantSystem);
1281 } else {
1282 defaultConstantValue = constantSystem.createNull();
1283 }
1284 if (!nameConstantValue.isString) {
1285 return new NonConstantValue();
1286 }
1287 StringConstantValue nameStringConstantValue = nameConstantValue;
1288 String text = environment.readFromEnvironment(
1289 nameStringConstantValue.primitiveValue.slowToString());
1214 int value; 1290 int value;
1215 String text = environment.readFromEnvironment(name);
1216 if (text != null) { 1291 if (text != null) {
1217 value = int.parse(text, onError: (_) => null); 1292 value = int.parse(text, onError: (_) => null);
1218 } 1293 }
1219 if (value == null) { 1294 if (value == null) {
1220 return defaultValue.evaluate(environment, constantSystem); 1295 return defaultConstantValue;
1221 } else { 1296 } else {
1222 return constantSystem.createInt(value); 1297 return constantSystem.createInt(value);
1223 } 1298 }
1224 } 1299 }
1225 1300
1226 ConstantExpression apply(NormalizedArguments arguments) { 1301 ConstantExpression apply(NormalizedArguments arguments) {
1227 return new IntFromEnvironmentConstantExpression( 1302 return new IntFromEnvironmentConstantExpression(
1228 null, name, defaultValue.apply(arguments)); 1303 null,
1304 name.apply(arguments),
1305 defaultValue != null ? defaultValue.apply(arguments) : null);
1229 } 1306 }
1230 } 1307 }
1231 1308
1232 /// A `const String.fromEnvironment` constant. 1309 /// A `const String.fromEnvironment` constant.
1233 class StringFromEnvironmentConstantExpression 1310 class StringFromEnvironmentConstantExpression
1234 extends FromEnvironmentConstantExpression { 1311 extends FromEnvironmentConstantExpression {
1235 1312
1236 StringFromEnvironmentConstantExpression( 1313 StringFromEnvironmentConstantExpression(
1237 ConstantValue value, 1314 ConstantValue value,
1238 String name, 1315 ConstantExpression name,
1239 ConstantExpression defaultValue) 1316 ConstantExpression defaultValue)
1240 : super(value, name, defaultValue); 1317 : super(value, name, defaultValue);
1241 1318
1242 ConstantExpressionKind get kind { 1319 ConstantExpressionKind get kind {
1243 return ConstantExpressionKind.STRING_FROM_ENVIRONMENT; 1320 return ConstantExpressionKind.STRING_FROM_ENVIRONMENT;
1244 } 1321 }
1245 1322
1246 accept(ConstantExpressionVisitor visitor, [context]) { 1323 accept(ConstantExpressionVisitor visitor, [context]) {
1247 return visitor.visitStringFromEnvironment(this, context); 1324 return visitor.visitStringFromEnvironment(this, context);
1248 } 1325 }
1249 1326
1250 @override 1327 @override
1251 ConstantValue evaluate(Environment environment, 1328 ConstantValue evaluate(Environment environment,
1252 ConstantSystem constantSystem) { 1329 ConstantSystem constantSystem) {
1253 String text = environment.readFromEnvironment(name); 1330 ConstantValue nameConstantValue =
1331 name.evaluate(environment, constantSystem);
1332 ConstantValue defaultConstantValue;
1333 if (defaultValue != null) {
1334 defaultConstantValue =
1335 defaultValue.evaluate(environment, constantSystem);
1336 } else {
1337 defaultConstantValue = constantSystem.createNull();
1338 }
1339 if (!nameConstantValue.isString) {
1340 return new NonConstantValue();
1341 }
1342 StringConstantValue nameStringConstantValue = nameConstantValue;
1343 String text = environment.readFromEnvironment(
1344 nameStringConstantValue.primitiveValue.slowToString());
1254 if (text == null) { 1345 if (text == null) {
1255 return defaultValue.evaluate(environment, constantSystem); 1346 return defaultConstantValue;
1256 } else { 1347 } else {
1257 return constantSystem.createString(new DartString.literal(text)); 1348 return constantSystem.createString(new DartString.literal(text));
1258 } 1349 }
1259 } 1350 }
1260 1351
1261 ConstantExpression apply(NormalizedArguments arguments) { 1352 ConstantExpression apply(NormalizedArguments arguments) {
1262 return new StringFromEnvironmentConstantExpression( 1353 return new StringFromEnvironmentConstantExpression(
1263 null, name, defaultValue.apply(arguments)); 1354 null,
1355 name.apply(arguments),
1356 defaultValue != null ? defaultValue.apply(arguments) : null);
1264 } 1357 }
1265 } 1358 }
1266 1359
1267 /// A constant expression referenced with a deferred prefix. 1360 /// A constant expression referenced with a deferred prefix.
1268 /// For example `lib.C`. 1361 /// For example `lib.C`.
1269 class DeferredConstantExpression extends ConstantExpression { 1362 class DeferredConstantExpression extends ConstantExpression {
1270 final ConstantValue value; 1363 final ConstantValue value;
1271 final ConstantExpression expression; 1364 final ConstantExpression expression;
1272 final PrefixElement prefix; 1365 final PrefixElement prefix;
1273 1366
1274 DeferredConstantExpression(this.value, this.expression, this.prefix); 1367 DeferredConstantExpression(this.value, this.expression, this.prefix);
1275 1368
1276 ConstantExpressionKind get kind => ConstantExpressionKind.DEFERRED; 1369 ConstantExpressionKind get kind => ConstantExpressionKind.DEFERRED;
1277 1370
1278 @override 1371 @override
1279 ConstantValue evaluate(Environment environment, 1372 ConstantValue evaluate(Environment environment,
1280 ConstantSystem constantSystem) { 1373 ConstantSystem constantSystem) {
1281 return expression.evaluate(environment, constantSystem); 1374 return expression.evaluate(environment, constantSystem);
1282 } 1375 }
1283 1376
1284 @override 1377 @override
1285 int _computeHashCode() { 1378 int _computeHashCode() {
1286 return 13 * expression.hashCode; 1379 return 13 * expression.hashCode;
1287 } 1380 }
1288 1381
1382 ConstantExpression apply(NormalizedArguments arguments) {
1383 return new DeferredConstantExpression(
1384 value, expression.apply(arguments), prefix);
1385 }
1386
1289 @override 1387 @override
1290 bool _equals(DeferredConstantExpression other) { 1388 bool _equals(DeferredConstantExpression other) {
1291 return expression == other.expression; 1389 return expression == other.expression;
1292 } 1390 }
1293 1391
1294 @override 1392 @override
1295 accept(ConstantExpressionVisitor visitor, [context]) { 1393 accept(ConstantExpressionVisitor visitor, [context]) {
1296 return visitor.visitDeferred(this, context); 1394 return visitor.visitDeferred(this, context);
1297 } 1395 }
1298 } 1396 }
(...skipping 14 matching lines...) Expand all
1313 R visitMap(MapConstantExpression exp, A context); 1411 R visitMap(MapConstantExpression exp, A context);
1314 R visitConstructed(ConstructedConstantExpression exp, A context); 1412 R visitConstructed(ConstructedConstantExpression exp, A context);
1315 R visitConcatenate(ConcatenateConstantExpression exp, A context); 1413 R visitConcatenate(ConcatenateConstantExpression exp, A context);
1316 R visitSymbol(SymbolConstantExpression exp, A context); 1414 R visitSymbol(SymbolConstantExpression exp, A context);
1317 R visitType(TypeConstantExpression exp, A context); 1415 R visitType(TypeConstantExpression exp, A context);
1318 R visitVariable(VariableConstantExpression exp, A context); 1416 R visitVariable(VariableConstantExpression exp, A context);
1319 R visitFunction(FunctionConstantExpression exp, A context); 1417 R visitFunction(FunctionConstantExpression exp, A context);
1320 R visitBinary(BinaryConstantExpression exp, A context); 1418 R visitBinary(BinaryConstantExpression exp, A context);
1321 R visitIdentical(IdenticalConstantExpression exp, A context); 1419 R visitIdentical(IdenticalConstantExpression exp, A context);
1322 R visitUnary(UnaryConstantExpression exp, A context); 1420 R visitUnary(UnaryConstantExpression exp, A context);
1421 R visitStringLength(StringLengthConstantExpression exp, A context);
1323 R visitConditional(ConditionalConstantExpression exp, A context); 1422 R visitConditional(ConditionalConstantExpression exp, A context);
1324 R visitBoolFromEnvironment(BoolFromEnvironmentConstantExpression exp, 1423 R visitBoolFromEnvironment(BoolFromEnvironmentConstantExpression exp,
1325 A context); 1424 A context);
1326 R visitIntFromEnvironment(IntFromEnvironmentConstantExpression exp, 1425 R visitIntFromEnvironment(IntFromEnvironmentConstantExpression exp,
1327 A context); 1426 A context);
1328 R visitStringFromEnvironment(StringFromEnvironmentConstantExpression exp, 1427 R visitStringFromEnvironment(StringFromEnvironmentConstantExpression exp,
1329 A context); 1428 A context);
1330 R visitDeferred(DeferredConstantExpression exp, A context); 1429 R visitDeferred(DeferredConstantExpression exp, A context);
1331 1430
1332 R visitPositional(PositionalArgumentReference exp, A context); 1431 R visitPositional(PositionalArgumentReference exp, A context);
1333 R visitNamed(NamedArgumentReference exp, A context); 1432 R visitNamed(NamedArgumentReference exp, A context);
1334 } 1433 }
1335 1434
1336 /// Represents the declaration of a constant [element] with value [expression]. 1435 /// Represents the declaration of a constant [element] with value [expression].
1337 // TODO(johnniwinther): Where does this class belong? 1436 // TODO(johnniwinther): Where does this class belong?
1338 class ConstDeclaration { 1437 class ConstDeclaration {
1339 final VariableElement element; 1438 final VariableElement element;
1340 final ConstantExpression expression; 1439 final ConstantExpression expression;
1341 1440
1342 ConstDeclaration(this.element, this.expression); 1441 ConstDeclaration(this.element, this.expression);
1343 } 1442 }
1344 1443
1345 class ConstExpPrinter extends ConstantExpressionVisitor { 1444 class ConstExpPrinter extends ConstantExpressionVisitor {
1346 final StringBuffer sb = new StringBuffer(); 1445 final StringBuffer sb = new StringBuffer();
1347 1446
1348 void write(ConstantExpression parent, 1447 void write(ConstantExpression parent,
1349 ConstantExpression child, 1448 ConstantExpression child,
1350 {bool leftAssociative: true}) { 1449 {bool leftAssociative: true}) {
1351 if (child.precedence < parent.precedence || 1450 if (child.precedence < parent.precedence ||
1352 !leftAssociative && child.precedence == parent.precedence) { 1451 !leftAssociative && child.precedence == parent.precedence) {
1353 sb.write('('); 1452 sb.write('(');
1354 child.accept(this); 1453 child.accept(this);
1355 sb.write(')'); 1454 sb.write(')');
1356 } else { 1455 } else {
1357 child.accept(this); 1456 child.accept(this);
1358 } 1457 }
1359 } 1458 }
1360 1459
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 sb.write(': '); 1535 sb.write(': ');
1437 visit(exp.values[index]); 1536 visit(exp.values[index]);
1438 } 1537 }
1439 sb.write('}'); 1538 sb.write('}');
1440 } 1539 }
1441 1540
1442 @override 1541 @override
1443 void visitConstructed(ConstructedConstantExpression exp, [_]) { 1542 void visitConstructed(ConstructedConstantExpression exp, [_]) {
1444 sb.write('const '); 1543 sb.write('const ');
1445 sb.write(exp.target.enclosingClass.name); 1544 sb.write(exp.target.enclosingClass.name);
1545 writeTypeArguments(exp.type);
1446 if (exp.target.name != '') { 1546 if (exp.target.name != '') {
1447 sb.write('.'); 1547 sb.write('.');
1448 sb.write(exp.target.name); 1548 sb.write(exp.target.name);
1449 } 1549 }
1450 writeTypeArguments(exp.type);
1451 sb.write('('); 1550 sb.write('(');
1452 bool needsComma = false; 1551 bool needsComma = false;
1453 1552
1454 int namedOffset = exp.callStructure.positionalArgumentCount; 1553 int namedOffset = exp.callStructure.positionalArgumentCount;
1455 for (int index = 0; index < namedOffset; index++) { 1554 for (int index = 0; index < namedOffset; index++) {
1456 if (needsComma) { 1555 if (needsComma) {
1457 sb.write(', '); 1556 sb.write(', ');
1458 } 1557 }
1459 visit(exp.arguments[index]); 1558 visit(exp.arguments[index]);
1460 needsComma = true; 1559 needsComma = true;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 sb.write(')'); 1622 sb.write(')');
1524 } 1623 }
1525 1624
1526 @override 1625 @override
1527 void visitUnary(UnaryConstantExpression exp, [_]) { 1626 void visitUnary(UnaryConstantExpression exp, [_]) {
1528 sb.write(exp.operator); 1627 sb.write(exp.operator);
1529 write(exp, exp.expression); 1628 write(exp, exp.expression);
1530 } 1629 }
1531 1630
1532 @override 1631 @override
1632 void visitStringLength(StringLengthConstantExpression exp, [_]) {
1633 write(exp, exp.expression, leftAssociative: false);
1634 sb.write('.length');
1635 }
1636
1637 @override
1533 void visitConditional(ConditionalConstantExpression exp, [_]) { 1638 void visitConditional(ConditionalConstantExpression exp, [_]) {
1534 write(exp, exp.condition, leftAssociative: false); 1639 write(exp, exp.condition, leftAssociative: false);
1535 sb.write(' ? '); 1640 sb.write(' ? ');
1536 write(exp, exp.trueExp); 1641 write(exp, exp.trueExp);
1537 sb.write(' : '); 1642 sb.write(' : ');
1538 write(exp, exp.falseExp); 1643 write(exp, exp.falseExp);
1539 } 1644 }
1540 1645
1541 @override 1646 @override
1542 void visitPositional(PositionalArgumentReference exp, [_]) { 1647 void visitPositional(PositionalArgumentReference exp, [_]) {
(...skipping 10 matching lines...) Expand all
1553 @override 1658 @override
1554 void visitDeferred(DeferredConstantExpression exp, context) { 1659 void visitDeferred(DeferredConstantExpression exp, context) {
1555 sb.write(exp.prefix.deferredImport.prefix.source); 1660 sb.write(exp.prefix.deferredImport.prefix.source);
1556 sb.write('.'); 1661 sb.write('.');
1557 write(exp, exp.expression); 1662 write(exp, exp.expression);
1558 } 1663 }
1559 1664
1560 @override 1665 @override
1561 void visitBoolFromEnvironment(BoolFromEnvironmentConstantExpression exp, 1666 void visitBoolFromEnvironment(BoolFromEnvironmentConstantExpression exp,
1562 [_]) { 1667 [_]) {
1563 sb.write('const bool.fromEnvironment("${exp.name}", defaultValue: '); 1668 sb.write('const bool.fromEnvironment(');
1564 visit(exp.defaultValue); 1669 visit(exp.name);
1670 if (exp.defaultValue != null) {
1671 sb.write(', defaultValue: ');
1672 visit(exp.defaultValue);
1673 }
1565 sb.write(')'); 1674 sb.write(')');
1566 } 1675 }
1567 1676
1568 @override 1677 @override
1569 void visitIntFromEnvironment(IntFromEnvironmentConstantExpression exp, [_]) { 1678 void visitIntFromEnvironment(IntFromEnvironmentConstantExpression exp, [_]) {
1570 sb.write('const int.fromEnvironment("${exp.name}", defaultValue: '); 1679 sb.write('const int.fromEnvironment(');
1571 visit(exp.defaultValue); 1680 visit(exp.name);
1681 if (exp.defaultValue != null) {
1682 sb.write(', defaultValue: ');
1683 visit(exp.defaultValue);
1684 }
1572 sb.write(')'); 1685 sb.write(')');
1573 } 1686 }
1574 1687
1575 @override 1688 @override
1576 void visitStringFromEnvironment(StringFromEnvironmentConstantExpression exp, 1689 void visitStringFromEnvironment(StringFromEnvironmentConstantExpression exp,
1577 [_]) { 1690 [_]) {
1578 sb.write('const String.fromEnvironment("${exp.name}", defaultValue: '); 1691 sb.write('const String.fromEnvironment(');
1579 visit(exp.defaultValue); 1692 visit(exp.name);
1693 if (exp.defaultValue != null) {
1694 sb.write(', defaultValue: ');
1695 visit(exp.defaultValue);
1696 }
1580 sb.write(')'); 1697 sb.write(')');
1581 } 1698 }
1582 1699
1583 String toString() => sb.toString(); 1700 String toString() => sb.toString();
1584 } 1701 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/compile_time_constants.dart ('k') | pkg/docgen/lib/src/models/model_helpers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698