| OLD | NEW |
| 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 '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
| 9 import '../core_types.dart'; | 9 import '../core_types.dart'; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 /// Compute the [ConstantValue] for this expression using the [environment] | 76 /// Compute the [ConstantValue] for this expression using the [environment] |
| 77 /// and the [constantSystem]. | 77 /// and the [constantSystem]. |
| 78 ConstantValue evaluate( | 78 ConstantValue evaluate( |
| 79 Environment environment, ConstantSystem constantSystem); | 79 Environment environment, ConstantSystem constantSystem); |
| 80 | 80 |
| 81 /// Returns the type of this constant expression, if it is independent of the | 81 /// Returns the type of this constant expression, if it is independent of the |
| 82 /// environment values. | 82 /// environment values. |
| 83 DartType getKnownType(CoreTypes coreTypes) => null; | 83 DartType getKnownType(CoreTypes coreTypes) => null; |
| 84 | 84 |
| 85 String getText() { | 85 /// Returns a text string resembling the Dart code creating this constant. |
| 86 String toDartText() { |
| 86 ConstExpPrinter printer = new ConstExpPrinter(); | 87 ConstExpPrinter printer = new ConstExpPrinter(); |
| 87 accept(printer); | 88 accept(printer); |
| 88 return printer.toString(); | 89 return printer.toString(); |
| 89 } | 90 } |
| 90 | 91 |
| 92 /// Returns a text string showing the structure of this constant. |
| 93 String toStructuredText() { |
| 94 StringBuffer sb = new StringBuffer(); |
| 95 _createStructuredText(sb); |
| 96 return sb.toString(); |
| 97 } |
| 98 |
| 99 /// Writes the structure of the constant into [sb]. |
| 100 void _createStructuredText(StringBuffer sb); |
| 101 |
| 91 int _computeHashCode(); | 102 int _computeHashCode(); |
| 92 | 103 |
| 93 int get hashCode { | 104 int get hashCode { |
| 94 if (_hashCode == null) { | 105 if (_hashCode == null) { |
| 95 _hashCode = _computeHashCode(); | 106 _hashCode = _computeHashCode(); |
| 96 } | 107 } |
| 97 return _hashCode; | 108 return _hashCode; |
| 98 } | 109 } |
| 99 | 110 |
| 100 bool _equals(ConstantExpression other); | 111 bool _equals(ConstantExpression other); |
| 101 | 112 |
| 102 bool operator ==(other) { | 113 bool operator ==(other) { |
| 103 if (identical(this, other)) return true; | 114 if (identical(this, other)) return true; |
| 104 if (other is! ConstantExpression) return false; | 115 if (other is! ConstantExpression) return false; |
| 105 if (kind != other.kind) return false; | 116 if (kind != other.kind) return false; |
| 106 if (hashCode != other.hashCode) return false; | 117 if (hashCode != other.hashCode) return false; |
| 107 return _equals(other); | 118 return _equals(other); |
| 108 } | 119 } |
| 109 | 120 |
| 110 String toString() { | 121 String toString() { |
| 111 assertDebugMode('Use ConstantExpression.getText() instead of ' | 122 assertDebugMode('Use ConstantExpression.toDartText() or ' |
| 123 'ConstantExpression.toStructuredText() instead of ' |
| 112 'ConstantExpression.toString()'); | 124 'ConstantExpression.toString()'); |
| 113 return getText(); | 125 return toDartText(); |
| 114 } | 126 } |
| 115 } | 127 } |
| 116 | 128 |
| 117 /// A synthetic constant used to recover from errors. | 129 /// A synthetic constant used to recover from errors. |
| 118 class ErroneousConstantExpression extends ConstantExpression { | 130 class ErroneousConstantExpression extends ConstantExpression { |
| 119 ConstantExpressionKind get kind => ConstantExpressionKind.ERRONEOUS; | 131 ConstantExpressionKind get kind => ConstantExpressionKind.ERRONEOUS; |
| 120 | 132 |
| 121 accept(ConstantExpressionVisitor visitor, [context]) { | 133 accept(ConstantExpressionVisitor visitor, [context]) { |
| 122 // Do nothing. This is an error. | 134 // Do nothing. This is an error. |
| 123 } | 135 } |
| 124 | 136 |
| 125 @override | 137 @override |
| 126 ConstantValue evaluate( | 138 ConstantValue evaluate( |
| 127 Environment environment, ConstantSystem constantSystem) { | 139 Environment environment, ConstantSystem constantSystem) { |
| 128 // TODO(johnniwinther): Use non-constant values for errors. | 140 // TODO(johnniwinther): Use non-constant values for errors. |
| 129 return new NonConstantValue(); | 141 return new NonConstantValue(); |
| 130 } | 142 } |
| 131 | 143 |
| 132 @override | 144 @override |
| 145 void _createStructuredText(StringBuffer sb) { |
| 146 sb.write('Erroneous()'); |
| 147 } |
| 148 |
| 149 @override |
| 133 int _computeHashCode() => 13; | 150 int _computeHashCode() => 13; |
| 134 | 151 |
| 135 @override | 152 @override |
| 136 bool _equals(ErroneousConstantExpression other) => true; | 153 bool _equals(ErroneousConstantExpression other) => true; |
| 137 } | 154 } |
| 138 | 155 |
| 139 // TODO(johnniwinther): Avoid the need for this class. | 156 // TODO(johnniwinther): Avoid the need for this class. |
| 140 class SyntheticConstantExpression extends ConstantExpression { | 157 class SyntheticConstantExpression extends ConstantExpression { |
| 141 final SyntheticConstantValue value; | 158 final SyntheticConstantValue value; |
| 142 | 159 |
| 143 SyntheticConstantExpression(this.value); | 160 SyntheticConstantExpression(this.value); |
| 144 | 161 |
| 145 @override | 162 @override |
| 146 ConstantValue evaluate( | 163 ConstantValue evaluate( |
| 147 Environment environment, ConstantSystem constantSystem) { | 164 Environment environment, ConstantSystem constantSystem) { |
| 148 return value; | 165 return value; |
| 149 } | 166 } |
| 150 | 167 |
| 151 @override | 168 @override |
| 169 void _createStructuredText(StringBuffer sb) { |
| 170 sb.write('Synthetic(value=${value.toStructuredText()})'); |
| 171 } |
| 172 |
| 173 @override |
| 152 int _computeHashCode() => 13 * value.hashCode; | 174 int _computeHashCode() => 13 * value.hashCode; |
| 153 | 175 |
| 154 accept(ConstantExpressionVisitor visitor, [context]) { | 176 accept(ConstantExpressionVisitor visitor, [context]) { |
| 155 throw "unsupported"; | 177 throw "unsupported"; |
| 156 } | 178 } |
| 157 | 179 |
| 158 @override | 180 @override |
| 159 bool _equals(SyntheticConstantExpression other) { | 181 bool _equals(SyntheticConstantExpression other) { |
| 160 return value == other.value; | 182 return value == other.value; |
| 161 } | 183 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 175 | 197 |
| 176 BoolConstantExpression(this.primitiveValue); | 198 BoolConstantExpression(this.primitiveValue); |
| 177 | 199 |
| 178 ConstantExpressionKind get kind => ConstantExpressionKind.BOOL; | 200 ConstantExpressionKind get kind => ConstantExpressionKind.BOOL; |
| 179 | 201 |
| 180 accept(ConstantExpressionVisitor visitor, [context]) { | 202 accept(ConstantExpressionVisitor visitor, [context]) { |
| 181 return visitor.visitBool(this, context); | 203 return visitor.visitBool(this, context); |
| 182 } | 204 } |
| 183 | 205 |
| 184 @override | 206 @override |
| 207 void _createStructuredText(StringBuffer sb) { |
| 208 sb.write('Bool(value=${primitiveValue})'); |
| 209 } |
| 210 |
| 211 @override |
| 185 ConstantValue evaluate( | 212 ConstantValue evaluate( |
| 186 Environment environment, ConstantSystem constantSystem) { | 213 Environment environment, ConstantSystem constantSystem) { |
| 187 return constantSystem.createBool(primitiveValue); | 214 return constantSystem.createBool(primitiveValue); |
| 188 } | 215 } |
| 189 | 216 |
| 190 @override | 217 @override |
| 191 int _computeHashCode() => 13 * primitiveValue.hashCode; | 218 int _computeHashCode() => 13 * primitiveValue.hashCode; |
| 192 | 219 |
| 193 @override | 220 @override |
| 194 bool _equals(BoolConstantExpression other) { | 221 bool _equals(BoolConstantExpression other) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 205 | 232 |
| 206 IntConstantExpression(this.primitiveValue); | 233 IntConstantExpression(this.primitiveValue); |
| 207 | 234 |
| 208 ConstantExpressionKind get kind => ConstantExpressionKind.INT; | 235 ConstantExpressionKind get kind => ConstantExpressionKind.INT; |
| 209 | 236 |
| 210 accept(ConstantExpressionVisitor visitor, [context]) { | 237 accept(ConstantExpressionVisitor visitor, [context]) { |
| 211 return visitor.visitInt(this, context); | 238 return visitor.visitInt(this, context); |
| 212 } | 239 } |
| 213 | 240 |
| 214 @override | 241 @override |
| 242 void _createStructuredText(StringBuffer sb) { |
| 243 sb.write('Int(value=${primitiveValue})'); |
| 244 } |
| 245 |
| 246 @override |
| 215 ConstantValue evaluate( | 247 ConstantValue evaluate( |
| 216 Environment environment, ConstantSystem constantSystem) { | 248 Environment environment, ConstantSystem constantSystem) { |
| 217 return constantSystem.createInt(primitiveValue); | 249 return constantSystem.createInt(primitiveValue); |
| 218 } | 250 } |
| 219 | 251 |
| 220 @override | 252 @override |
| 221 int _computeHashCode() => 17 * primitiveValue.hashCode; | 253 int _computeHashCode() => 17 * primitiveValue.hashCode; |
| 222 | 254 |
| 223 @override | 255 @override |
| 224 bool _equals(IntConstantExpression other) { | 256 bool _equals(IntConstantExpression other) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 235 | 267 |
| 236 DoubleConstantExpression(this.primitiveValue); | 268 DoubleConstantExpression(this.primitiveValue); |
| 237 | 269 |
| 238 ConstantExpressionKind get kind => ConstantExpressionKind.DOUBLE; | 270 ConstantExpressionKind get kind => ConstantExpressionKind.DOUBLE; |
| 239 | 271 |
| 240 accept(ConstantExpressionVisitor visitor, [context]) { | 272 accept(ConstantExpressionVisitor visitor, [context]) { |
| 241 return visitor.visitDouble(this, context); | 273 return visitor.visitDouble(this, context); |
| 242 } | 274 } |
| 243 | 275 |
| 244 @override | 276 @override |
| 277 void _createStructuredText(StringBuffer sb) { |
| 278 sb.write('Double(value=${primitiveValue})'); |
| 279 } |
| 280 |
| 281 @override |
| 245 ConstantValue evaluate( | 282 ConstantValue evaluate( |
| 246 Environment environment, ConstantSystem constantSystem) { | 283 Environment environment, ConstantSystem constantSystem) { |
| 247 return constantSystem.createDouble(primitiveValue); | 284 return constantSystem.createDouble(primitiveValue); |
| 248 } | 285 } |
| 249 | 286 |
| 250 @override | 287 @override |
| 251 int _computeHashCode() => 19 * primitiveValue.hashCode; | 288 int _computeHashCode() => 19 * primitiveValue.hashCode; |
| 252 | 289 |
| 253 @override | 290 @override |
| 254 bool _equals(DoubleConstantExpression other) { | 291 bool _equals(DoubleConstantExpression other) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 265 | 302 |
| 266 StringConstantExpression(this.primitiveValue); | 303 StringConstantExpression(this.primitiveValue); |
| 267 | 304 |
| 268 ConstantExpressionKind get kind => ConstantExpressionKind.STRING; | 305 ConstantExpressionKind get kind => ConstantExpressionKind.STRING; |
| 269 | 306 |
| 270 accept(ConstantExpressionVisitor visitor, [context]) { | 307 accept(ConstantExpressionVisitor visitor, [context]) { |
| 271 return visitor.visitString(this, context); | 308 return visitor.visitString(this, context); |
| 272 } | 309 } |
| 273 | 310 |
| 274 @override | 311 @override |
| 312 void _createStructuredText(StringBuffer sb) { |
| 313 sb.write('String(value=${primitiveValue})'); |
| 314 } |
| 315 |
| 316 @override |
| 275 ConstantValue evaluate( | 317 ConstantValue evaluate( |
| 276 Environment environment, ConstantSystem constantSystem) { | 318 Environment environment, ConstantSystem constantSystem) { |
| 277 return constantSystem.createString(new DartString.literal(primitiveValue)); | 319 return constantSystem.createString(new DartString.literal(primitiveValue)); |
| 278 } | 320 } |
| 279 | 321 |
| 280 @override | 322 @override |
| 281 int _computeHashCode() => 23 * primitiveValue.hashCode; | 323 int _computeHashCode() => 23 * primitiveValue.hashCode; |
| 282 | 324 |
| 283 @override | 325 @override |
| 284 bool _equals(StringConstantExpression other) { | 326 bool _equals(StringConstantExpression other) { |
| 285 return primitiveValue == other.primitiveValue; | 327 return primitiveValue == other.primitiveValue; |
| 286 } | 328 } |
| 287 | 329 |
| 288 @override | 330 @override |
| 289 DartType getKnownType(CoreTypes coreTypes) => coreTypes.stringType; | 331 DartType getKnownType(CoreTypes coreTypes) => coreTypes.stringType; |
| 290 } | 332 } |
| 291 | 333 |
| 292 /// Null literal constant. | 334 /// Null literal constant. |
| 293 class NullConstantExpression extends PrimitiveConstantExpression { | 335 class NullConstantExpression extends PrimitiveConstantExpression { |
| 294 NullConstantExpression(); | 336 NullConstantExpression(); |
| 295 | 337 |
| 296 ConstantExpressionKind get kind => ConstantExpressionKind.NULL; | 338 ConstantExpressionKind get kind => ConstantExpressionKind.NULL; |
| 297 | 339 |
| 298 accept(ConstantExpressionVisitor visitor, [context]) { | 340 accept(ConstantExpressionVisitor visitor, [context]) { |
| 299 return visitor.visitNull(this, context); | 341 return visitor.visitNull(this, context); |
| 300 } | 342 } |
| 301 | 343 |
| 302 @override | 344 @override |
| 345 void _createStructuredText(StringBuffer sb) { |
| 346 sb.write('Null()'); |
| 347 } |
| 348 |
| 349 @override |
| 303 ConstantValue evaluate( | 350 ConstantValue evaluate( |
| 304 Environment environment, ConstantSystem constantSystem) { | 351 Environment environment, ConstantSystem constantSystem) { |
| 305 return constantSystem.createNull(); | 352 return constantSystem.createNull(); |
| 306 } | 353 } |
| 307 | 354 |
| 308 get primitiveValue => null; | 355 get primitiveValue => null; |
| 309 | 356 |
| 310 @override | 357 @override |
| 311 int _computeHashCode() => 29; | 358 int _computeHashCode() => 29; |
| 312 | 359 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 324 | 371 |
| 325 ListConstantExpression(this.type, this.values); | 372 ListConstantExpression(this.type, this.values); |
| 326 | 373 |
| 327 ConstantExpressionKind get kind => ConstantExpressionKind.LIST; | 374 ConstantExpressionKind get kind => ConstantExpressionKind.LIST; |
| 328 | 375 |
| 329 accept(ConstantExpressionVisitor visitor, [context]) { | 376 accept(ConstantExpressionVisitor visitor, [context]) { |
| 330 return visitor.visitList(this, context); | 377 return visitor.visitList(this, context); |
| 331 } | 378 } |
| 332 | 379 |
| 333 @override | 380 @override |
| 381 void _createStructuredText(StringBuffer sb) { |
| 382 sb.write('List(type=$type,values=['); |
| 383 String delimiter = ''; |
| 384 for (ConstantExpression value in values) { |
| 385 sb.write(delimiter); |
| 386 value._createStructuredText(sb); |
| 387 delimiter = ','; |
| 388 } |
| 389 sb.write('])'); |
| 390 } |
| 391 |
| 392 @override |
| 334 ConstantValue evaluate( | 393 ConstantValue evaluate( |
| 335 Environment environment, ConstantSystem constantSystem) { | 394 Environment environment, ConstantSystem constantSystem) { |
| 336 return constantSystem.createList(type, | 395 return constantSystem.createList(type, |
| 337 values.map((v) => v.evaluate(environment, constantSystem)).toList()); | 396 values.map((v) => v.evaluate(environment, constantSystem)).toList()); |
| 338 } | 397 } |
| 339 | 398 |
| 340 ConstantExpression apply(NormalizedArguments arguments) { | 399 ConstantExpression apply(NormalizedArguments arguments) { |
| 341 return new ListConstantExpression( | 400 return new ListConstantExpression( |
| 342 type, values.map((v) => v.apply(arguments)).toList()); | 401 type, values.map((v) => v.apply(arguments)).toList()); |
| 343 } | 402 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 373 | 432 |
| 374 MapConstantExpression(this.type, this.keys, this.values); | 433 MapConstantExpression(this.type, this.keys, this.values); |
| 375 | 434 |
| 376 ConstantExpressionKind get kind => ConstantExpressionKind.MAP; | 435 ConstantExpressionKind get kind => ConstantExpressionKind.MAP; |
| 377 | 436 |
| 378 accept(ConstantExpressionVisitor visitor, [context]) { | 437 accept(ConstantExpressionVisitor visitor, [context]) { |
| 379 return visitor.visitMap(this, context); | 438 return visitor.visitMap(this, context); |
| 380 } | 439 } |
| 381 | 440 |
| 382 @override | 441 @override |
| 442 void _createStructuredText(StringBuffer sb) { |
| 443 sb.write('Map(type=$type,entries=['); |
| 444 for (int index = 0; index < keys.length; index++) { |
| 445 if (index > 0) { |
| 446 sb.write(','); |
| 447 } |
| 448 keys[index]._createStructuredText(sb); |
| 449 sb.write('->'); |
| 450 values[index]._createStructuredText(sb); |
| 451 } |
| 452 sb.write('])'); |
| 453 } |
| 454 |
| 455 @override |
| 383 ConstantValue evaluate( | 456 ConstantValue evaluate( |
| 384 Environment environment, ConstantSystem constantSystem) { | 457 Environment environment, ConstantSystem constantSystem) { |
| 385 return constantSystem.createMap( | 458 return constantSystem.createMap( |
| 386 environment.compiler, | 459 environment.compiler, |
| 387 type, | 460 type, |
| 388 keys.map((k) => k.evaluate(environment, constantSystem)).toList(), | 461 keys.map((k) => k.evaluate(environment, constantSystem)).toList(), |
| 389 values.map((v) => v.evaluate(environment, constantSystem)).toList()); | 462 values.map((v) => v.evaluate(environment, constantSystem)).toList()); |
| 390 } | 463 } |
| 391 | 464 |
| 392 ConstantExpression apply(NormalizedArguments arguments) { | 465 ConstantExpression apply(NormalizedArguments arguments) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 assert(type.element == target.enclosingClass); | 505 assert(type.element == target.enclosingClass); |
| 433 assert(!arguments.contains(null)); | 506 assert(!arguments.contains(null)); |
| 434 } | 507 } |
| 435 | 508 |
| 436 ConstantExpressionKind get kind => ConstantExpressionKind.CONSTRUCTED; | 509 ConstantExpressionKind get kind => ConstantExpressionKind.CONSTRUCTED; |
| 437 | 510 |
| 438 accept(ConstantExpressionVisitor visitor, [context]) { | 511 accept(ConstantExpressionVisitor visitor, [context]) { |
| 439 return visitor.visitConstructed(this, context); | 512 return visitor.visitConstructed(this, context); |
| 440 } | 513 } |
| 441 | 514 |
| 515 @override |
| 516 void _createStructuredText(StringBuffer sb) { |
| 517 sb.write('Constructored(type=$type,constructor=$target,' |
| 518 'callStructure=$callStructure,arguments=['); |
| 519 String delimiter = ''; |
| 520 for (ConstantExpression value in arguments) { |
| 521 sb.write(delimiter); |
| 522 value._createStructuredText(sb); |
| 523 delimiter = ','; |
| 524 } |
| 525 sb.write('])'); |
| 526 } |
| 527 |
| 442 Map<FieldElement, ConstantExpression> computeInstanceFields() { | 528 Map<FieldElement, ConstantExpression> computeInstanceFields() { |
| 443 return target.constantConstructor | 529 return target.constantConstructor |
| 444 .computeInstanceFields(arguments, callStructure); | 530 .computeInstanceFields(arguments, callStructure); |
| 445 } | 531 } |
| 446 | 532 |
| 447 InterfaceType computeInstanceType() { | 533 InterfaceType computeInstanceType() { |
| 448 return target.constantConstructor.computeInstanceType(type); | 534 return target.constantConstructor.computeInstanceType(type); |
| 449 } | 535 } |
| 450 | 536 |
| 451 ConstructedConstantExpression apply(NormalizedArguments arguments) { | 537 ConstructedConstantExpression apply(NormalizedArguments arguments) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 final List<ConstantExpression> expressions; | 578 final List<ConstantExpression> expressions; |
| 493 | 579 |
| 494 ConcatenateConstantExpression(this.expressions); | 580 ConcatenateConstantExpression(this.expressions); |
| 495 | 581 |
| 496 ConstantExpressionKind get kind => ConstantExpressionKind.CONCATENATE; | 582 ConstantExpressionKind get kind => ConstantExpressionKind.CONCATENATE; |
| 497 | 583 |
| 498 accept(ConstantExpressionVisitor visitor, [context]) { | 584 accept(ConstantExpressionVisitor visitor, [context]) { |
| 499 return visitor.visitConcatenate(this, context); | 585 return visitor.visitConcatenate(this, context); |
| 500 } | 586 } |
| 501 | 587 |
| 588 @override |
| 589 void _createStructuredText(StringBuffer sb) { |
| 590 sb.write('Concatenate(expressions=['); |
| 591 String delimiter = ''; |
| 592 for (ConstantExpression value in expressions) { |
| 593 sb.write(delimiter); |
| 594 value._createStructuredText(sb); |
| 595 delimiter = ','; |
| 596 } |
| 597 sb.write('])'); |
| 598 } |
| 599 |
| 502 ConstantExpression apply(NormalizedArguments arguments) { | 600 ConstantExpression apply(NormalizedArguments arguments) { |
| 503 return new ConcatenateConstantExpression( | 601 return new ConcatenateConstantExpression( |
| 504 expressions.map((a) => a.apply(arguments)).toList()); | 602 expressions.map((a) => a.apply(arguments)).toList()); |
| 505 } | 603 } |
| 506 | 604 |
| 507 @override | 605 @override |
| 508 ConstantValue evaluate( | 606 ConstantValue evaluate( |
| 509 Environment environment, ConstantSystem constantSystem) { | 607 Environment environment, ConstantSystem constantSystem) { |
| 510 DartString accumulator; | 608 DartString accumulator; |
| 511 for (ConstantExpression expression in expressions) { | 609 for (ConstantExpression expression in expressions) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 | 658 |
| 561 SymbolConstantExpression(this.name); | 659 SymbolConstantExpression(this.name); |
| 562 | 660 |
| 563 ConstantExpressionKind get kind => ConstantExpressionKind.SYMBOL; | 661 ConstantExpressionKind get kind => ConstantExpressionKind.SYMBOL; |
| 564 | 662 |
| 565 accept(ConstantExpressionVisitor visitor, [context]) { | 663 accept(ConstantExpressionVisitor visitor, [context]) { |
| 566 return visitor.visitSymbol(this, context); | 664 return visitor.visitSymbol(this, context); |
| 567 } | 665 } |
| 568 | 666 |
| 569 @override | 667 @override |
| 668 void _createStructuredText(StringBuffer sb) { |
| 669 sb.write('Symbol(name=$name)'); |
| 670 } |
| 671 |
| 672 @override |
| 570 int _computeHashCode() => 13 * name.hashCode; | 673 int _computeHashCode() => 13 * name.hashCode; |
| 571 | 674 |
| 572 @override | 675 @override |
| 573 bool _equals(SymbolConstantExpression other) { | 676 bool _equals(SymbolConstantExpression other) { |
| 574 return name == other.name; | 677 return name == other.name; |
| 575 } | 678 } |
| 576 | 679 |
| 577 @override | 680 @override |
| 578 ConstantValue evaluate( | 681 ConstantValue evaluate( |
| 579 Environment environment, ConstantSystem constantSystem) { | 682 Environment environment, ConstantSystem constantSystem) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 594 assert(type is GenericType || type is DynamicType); | 697 assert(type is GenericType || type is DynamicType); |
| 595 } | 698 } |
| 596 | 699 |
| 597 ConstantExpressionKind get kind => ConstantExpressionKind.TYPE; | 700 ConstantExpressionKind get kind => ConstantExpressionKind.TYPE; |
| 598 | 701 |
| 599 accept(ConstantExpressionVisitor visitor, [context]) { | 702 accept(ConstantExpressionVisitor visitor, [context]) { |
| 600 return visitor.visitType(this, context); | 703 return visitor.visitType(this, context); |
| 601 } | 704 } |
| 602 | 705 |
| 603 @override | 706 @override |
| 707 void _createStructuredText(StringBuffer sb) { |
| 708 sb.write('Type(type=$type)'); |
| 709 } |
| 710 |
| 711 @override |
| 604 ConstantValue evaluate( | 712 ConstantValue evaluate( |
| 605 Environment environment, ConstantSystem constantSystem) { | 713 Environment environment, ConstantSystem constantSystem) { |
| 606 return constantSystem.createType(environment.compiler, type); | 714 return constantSystem.createType(environment.compiler, type); |
| 607 } | 715 } |
| 608 | 716 |
| 609 @override | 717 @override |
| 610 int _computeHashCode() => 13 * type.hashCode; | 718 int _computeHashCode() => 13 * type.hashCode; |
| 611 | 719 |
| 612 @override | 720 @override |
| 613 bool _equals(TypeConstantExpression other) { | 721 bool _equals(TypeConstantExpression other) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 624 | 732 |
| 625 VariableConstantExpression(this.element); | 733 VariableConstantExpression(this.element); |
| 626 | 734 |
| 627 ConstantExpressionKind get kind => ConstantExpressionKind.VARIABLE; | 735 ConstantExpressionKind get kind => ConstantExpressionKind.VARIABLE; |
| 628 | 736 |
| 629 accept(ConstantExpressionVisitor visitor, [context]) { | 737 accept(ConstantExpressionVisitor visitor, [context]) { |
| 630 return visitor.visitVariable(this, context); | 738 return visitor.visitVariable(this, context); |
| 631 } | 739 } |
| 632 | 740 |
| 633 @override | 741 @override |
| 742 void _createStructuredText(StringBuffer sb) { |
| 743 sb.write('Variable(element=$element)'); |
| 744 } |
| 745 |
| 746 @override |
| 634 ConstantValue evaluate( | 747 ConstantValue evaluate( |
| 635 Environment environment, ConstantSystem constantSystem) { | 748 Environment environment, ConstantSystem constantSystem) { |
| 636 return element.constant.evaluate(environment, constantSystem); | 749 return element.constant.evaluate(environment, constantSystem); |
| 637 } | 750 } |
| 638 | 751 |
| 639 @override | 752 @override |
| 640 int _computeHashCode() => 13 * element.hashCode; | 753 int _computeHashCode() => 13 * element.hashCode; |
| 641 | 754 |
| 642 @override | 755 @override |
| 643 bool _equals(VariableConstantExpression other) { | 756 bool _equals(VariableConstantExpression other) { |
| 644 return element == other.element; | 757 return element == other.element; |
| 645 } | 758 } |
| 646 } | 759 } |
| 647 | 760 |
| 648 /// Reference to a top-level or static function. | 761 /// Reference to a top-level or static function. |
| 649 class FunctionConstantExpression extends ConstantExpression { | 762 class FunctionConstantExpression extends ConstantExpression { |
| 650 final FunctionElement element; | 763 final FunctionElement element; |
| 651 | 764 |
| 652 FunctionConstantExpression(this.element); | 765 FunctionConstantExpression(this.element); |
| 653 | 766 |
| 654 ConstantExpressionKind get kind => ConstantExpressionKind.FUNCTION; | 767 ConstantExpressionKind get kind => ConstantExpressionKind.FUNCTION; |
| 655 | 768 |
| 656 accept(ConstantExpressionVisitor visitor, [context]) { | 769 accept(ConstantExpressionVisitor visitor, [context]) { |
| 657 return visitor.visitFunction(this, context); | 770 return visitor.visitFunction(this, context); |
| 658 } | 771 } |
| 659 | 772 |
| 660 @override | 773 @override |
| 774 void _createStructuredText(StringBuffer sb) { |
| 775 sb.write('Function(element=$element)'); |
| 776 } |
| 777 |
| 778 @override |
| 661 ConstantValue evaluate( | 779 ConstantValue evaluate( |
| 662 Environment environment, ConstantSystem constantSystem) { | 780 Environment environment, ConstantSystem constantSystem) { |
| 663 return new FunctionConstantValue(element); | 781 return new FunctionConstantValue(element); |
| 664 } | 782 } |
| 665 | 783 |
| 666 @override | 784 @override |
| 667 int _computeHashCode() => 13 * element.hashCode; | 785 int _computeHashCode() => 13 * element.hashCode; |
| 668 | 786 |
| 669 @override | 787 @override |
| 670 bool _equals(FunctionConstantExpression other) { | 788 bool _equals(FunctionConstantExpression other) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 685 assert(PRECEDENCE_MAP[operator.kind] != null); | 803 assert(PRECEDENCE_MAP[operator.kind] != null); |
| 686 } | 804 } |
| 687 | 805 |
| 688 ConstantExpressionKind get kind => ConstantExpressionKind.BINARY; | 806 ConstantExpressionKind get kind => ConstantExpressionKind.BINARY; |
| 689 | 807 |
| 690 accept(ConstantExpressionVisitor visitor, [context]) { | 808 accept(ConstantExpressionVisitor visitor, [context]) { |
| 691 return visitor.visitBinary(this, context); | 809 return visitor.visitBinary(this, context); |
| 692 } | 810 } |
| 693 | 811 |
| 694 @override | 812 @override |
| 813 void _createStructuredText(StringBuffer sb) { |
| 814 sb.write('Binary(left='); |
| 815 left._createStructuredText(sb); |
| 816 sb.write(',op=$operator,right='); |
| 817 right._createStructuredText(sb); |
| 818 sb.write(')'); |
| 819 } |
| 820 |
| 821 @override |
| 695 ConstantValue evaluate( | 822 ConstantValue evaluate( |
| 696 Environment environment, ConstantSystem constantSystem) { | 823 Environment environment, ConstantSystem constantSystem) { |
| 697 return constantSystem.lookupBinary(operator).fold( | 824 return constantSystem.lookupBinary(operator).fold( |
| 698 left.evaluate(environment, constantSystem), | 825 left.evaluate(environment, constantSystem), |
| 699 right.evaluate(environment, constantSystem)); | 826 right.evaluate(environment, constantSystem)); |
| 700 } | 827 } |
| 701 | 828 |
| 702 ConstantExpression apply(NormalizedArguments arguments) { | 829 ConstantExpression apply(NormalizedArguments arguments) { |
| 703 return new BinaryConstantExpression( | 830 return new BinaryConstantExpression( |
| 704 left.apply(arguments), operator, right.apply(arguments)); | 831 left.apply(arguments), operator, right.apply(arguments)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 | 927 |
| 801 IdenticalConstantExpression(this.left, this.right); | 928 IdenticalConstantExpression(this.left, this.right); |
| 802 | 929 |
| 803 ConstantExpressionKind get kind => ConstantExpressionKind.IDENTICAL; | 930 ConstantExpressionKind get kind => ConstantExpressionKind.IDENTICAL; |
| 804 | 931 |
| 805 accept(ConstantExpressionVisitor visitor, [context]) { | 932 accept(ConstantExpressionVisitor visitor, [context]) { |
| 806 return visitor.visitIdentical(this, context); | 933 return visitor.visitIdentical(this, context); |
| 807 } | 934 } |
| 808 | 935 |
| 809 @override | 936 @override |
| 937 void _createStructuredText(StringBuffer sb) { |
| 938 sb.write('Identical(left='); |
| 939 left._createStructuredText(sb); |
| 940 sb.write(',right='); |
| 941 right._createStructuredText(sb); |
| 942 sb.write(')'); |
| 943 } |
| 944 |
| 945 @override |
| 810 ConstantValue evaluate( | 946 ConstantValue evaluate( |
| 811 Environment environment, ConstantSystem constantSystem) { | 947 Environment environment, ConstantSystem constantSystem) { |
| 812 return constantSystem.identity.fold( | 948 return constantSystem.identity.fold( |
| 813 left.evaluate(environment, constantSystem), | 949 left.evaluate(environment, constantSystem), |
| 814 right.evaluate(environment, constantSystem)); | 950 right.evaluate(environment, constantSystem)); |
| 815 } | 951 } |
| 816 | 952 |
| 817 ConstantExpression apply(NormalizedArguments arguments) { | 953 ConstantExpression apply(NormalizedArguments arguments) { |
| 818 return new IdenticalConstantExpression( | 954 return new IdenticalConstantExpression( |
| 819 left.apply(arguments), right.apply(arguments)); | 955 left.apply(arguments), right.apply(arguments)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 844 assert(PRECEDENCE_MAP[operator.kind] != null); | 980 assert(PRECEDENCE_MAP[operator.kind] != null); |
| 845 } | 981 } |
| 846 | 982 |
| 847 ConstantExpressionKind get kind => ConstantExpressionKind.UNARY; | 983 ConstantExpressionKind get kind => ConstantExpressionKind.UNARY; |
| 848 | 984 |
| 849 accept(ConstantExpressionVisitor visitor, [context]) { | 985 accept(ConstantExpressionVisitor visitor, [context]) { |
| 850 return visitor.visitUnary(this, context); | 986 return visitor.visitUnary(this, context); |
| 851 } | 987 } |
| 852 | 988 |
| 853 @override | 989 @override |
| 990 void _createStructuredText(StringBuffer sb) { |
| 991 sb.write('Unary(op=$operator,expression='); |
| 992 expression._createStructuredText(sb); |
| 993 sb.write(')'); |
| 994 } |
| 995 |
| 996 @override |
| 854 ConstantValue evaluate( | 997 ConstantValue evaluate( |
| 855 Environment environment, ConstantSystem constantSystem) { | 998 Environment environment, ConstantSystem constantSystem) { |
| 856 return constantSystem | 999 return constantSystem |
| 857 .lookupUnary(operator) | 1000 .lookupUnary(operator) |
| 858 .fold(expression.evaluate(environment, constantSystem)); | 1001 .fold(expression.evaluate(environment, constantSystem)); |
| 859 } | 1002 } |
| 860 | 1003 |
| 861 ConstantExpression apply(NormalizedArguments arguments) { | 1004 ConstantExpression apply(NormalizedArguments arguments) { |
| 862 return new UnaryConstantExpression(operator, expression.apply(arguments)); | 1005 return new UnaryConstantExpression(operator, expression.apply(arguments)); |
| 863 } | 1006 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 892 | 1035 |
| 893 StringLengthConstantExpression(this.expression); | 1036 StringLengthConstantExpression(this.expression); |
| 894 | 1037 |
| 895 ConstantExpressionKind get kind => ConstantExpressionKind.STRING_LENGTH; | 1038 ConstantExpressionKind get kind => ConstantExpressionKind.STRING_LENGTH; |
| 896 | 1039 |
| 897 accept(ConstantExpressionVisitor visitor, [context]) { | 1040 accept(ConstantExpressionVisitor visitor, [context]) { |
| 898 return visitor.visitStringLength(this, context); | 1041 return visitor.visitStringLength(this, context); |
| 899 } | 1042 } |
| 900 | 1043 |
| 901 @override | 1044 @override |
| 1045 void _createStructuredText(StringBuffer sb) { |
| 1046 sb.write('StringLength(expression='); |
| 1047 expression._createStructuredText(sb); |
| 1048 sb.write(')'); |
| 1049 } |
| 1050 |
| 1051 @override |
| 902 ConstantValue evaluate( | 1052 ConstantValue evaluate( |
| 903 Environment environment, ConstantSystem constantSystem) { | 1053 Environment environment, ConstantSystem constantSystem) { |
| 904 ConstantValue value = expression.evaluate(environment, constantSystem); | 1054 ConstantValue value = expression.evaluate(environment, constantSystem); |
| 905 if (value.isString) { | 1055 if (value.isString) { |
| 906 StringConstantValue stringValue = value; | 1056 StringConstantValue stringValue = value; |
| 907 return constantSystem.createInt(stringValue.primitiveValue.length); | 1057 return constantSystem.createInt(stringValue.primitiveValue.length); |
| 908 } | 1058 } |
| 909 return new NonConstantValue(); | 1059 return new NonConstantValue(); |
| 910 } | 1060 } |
| 911 | 1061 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 936 final ConstantExpression falseExp; | 1086 final ConstantExpression falseExp; |
| 937 | 1087 |
| 938 ConditionalConstantExpression(this.condition, this.trueExp, this.falseExp); | 1088 ConditionalConstantExpression(this.condition, this.trueExp, this.falseExp); |
| 939 | 1089 |
| 940 ConstantExpressionKind get kind => ConstantExpressionKind.CONDITIONAL; | 1090 ConstantExpressionKind get kind => ConstantExpressionKind.CONDITIONAL; |
| 941 | 1091 |
| 942 accept(ConstantExpressionVisitor visitor, [context]) { | 1092 accept(ConstantExpressionVisitor visitor, [context]) { |
| 943 return visitor.visitConditional(this, context); | 1093 return visitor.visitConditional(this, context); |
| 944 } | 1094 } |
| 945 | 1095 |
| 1096 @override |
| 1097 void _createStructuredText(StringBuffer sb) { |
| 1098 sb.write('Conditional(condition='); |
| 1099 condition._createStructuredText(sb); |
| 1100 sb.write(',true='); |
| 1101 trueExp._createStructuredText(sb); |
| 1102 sb.write(',false='); |
| 1103 falseExp._createStructuredText(sb); |
| 1104 sb.write(')'); |
| 1105 } |
| 1106 |
| 946 ConstantExpression apply(NormalizedArguments arguments) { | 1107 ConstantExpression apply(NormalizedArguments arguments) { |
| 947 return new ConditionalConstantExpression(condition.apply(arguments), | 1108 return new ConditionalConstantExpression(condition.apply(arguments), |
| 948 trueExp.apply(arguments), falseExp.apply(arguments)); | 1109 trueExp.apply(arguments), falseExp.apply(arguments)); |
| 949 } | 1110 } |
| 950 | 1111 |
| 951 int get precedence => 3; | 1112 int get precedence => 3; |
| 952 | 1113 |
| 953 @override | 1114 @override |
| 954 int _computeHashCode() { | 1115 int _computeHashCode() { |
| 955 return 13 * condition.hashCode + | 1116 return 13 * condition.hashCode + |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 PositionalArgumentReference(this.index); | 1159 PositionalArgumentReference(this.index); |
| 999 | 1160 |
| 1000 ConstantExpressionKind get kind { | 1161 ConstantExpressionKind get kind { |
| 1001 return ConstantExpressionKind.POSITIONAL_REFERENCE; | 1162 return ConstantExpressionKind.POSITIONAL_REFERENCE; |
| 1002 } | 1163 } |
| 1003 | 1164 |
| 1004 accept(ConstantExpressionVisitor visitor, [context]) { | 1165 accept(ConstantExpressionVisitor visitor, [context]) { |
| 1005 return visitor.visitPositional(this, context); | 1166 return visitor.visitPositional(this, context); |
| 1006 } | 1167 } |
| 1007 | 1168 |
| 1169 @override |
| 1170 void _createStructuredText(StringBuffer sb) { |
| 1171 sb.write('Positional(index=$index)'); |
| 1172 } |
| 1173 |
| 1008 ConstantExpression apply(NormalizedArguments arguments) { | 1174 ConstantExpression apply(NormalizedArguments arguments) { |
| 1009 return arguments.getPositionalArgument(index); | 1175 return arguments.getPositionalArgument(index); |
| 1010 } | 1176 } |
| 1011 | 1177 |
| 1012 @override | 1178 @override |
| 1013 int _computeHashCode() => 13 * index.hashCode; | 1179 int _computeHashCode() => 13 * index.hashCode; |
| 1014 | 1180 |
| 1015 @override | 1181 @override |
| 1016 bool _equals(PositionalArgumentReference other) => index == other.index; | 1182 bool _equals(PositionalArgumentReference other) => index == other.index; |
| 1017 | 1183 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1029 NamedArgumentReference(this.name); | 1195 NamedArgumentReference(this.name); |
| 1030 | 1196 |
| 1031 ConstantExpressionKind get kind { | 1197 ConstantExpressionKind get kind { |
| 1032 return ConstantExpressionKind.NAMED_REFERENCE; | 1198 return ConstantExpressionKind.NAMED_REFERENCE; |
| 1033 } | 1199 } |
| 1034 | 1200 |
| 1035 accept(ConstantExpressionVisitor visitor, [context]) { | 1201 accept(ConstantExpressionVisitor visitor, [context]) { |
| 1036 return visitor.visitNamed(this, context); | 1202 return visitor.visitNamed(this, context); |
| 1037 } | 1203 } |
| 1038 | 1204 |
| 1205 @override |
| 1206 void _createStructuredText(StringBuffer sb) { |
| 1207 sb.write('Named(name=$name)'); |
| 1208 } |
| 1209 |
| 1039 ConstantExpression apply(NormalizedArguments arguments) { | 1210 ConstantExpression apply(NormalizedArguments arguments) { |
| 1040 return arguments.getNamedArgument(name); | 1211 return arguments.getNamedArgument(name); |
| 1041 } | 1212 } |
| 1042 | 1213 |
| 1043 @override | 1214 @override |
| 1044 int _computeHashCode() => 13 * name.hashCode; | 1215 int _computeHashCode() => 13 * name.hashCode; |
| 1045 | 1216 |
| 1046 @override | 1217 @override |
| 1047 bool _equals(NamedArgumentReference other) => name == other.name; | 1218 bool _equals(NamedArgumentReference other) => name == other.name; |
| 1048 | 1219 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1079 | 1250 |
| 1080 ConstantExpressionKind get kind { | 1251 ConstantExpressionKind get kind { |
| 1081 return ConstantExpressionKind.BOOL_FROM_ENVIRONMENT; | 1252 return ConstantExpressionKind.BOOL_FROM_ENVIRONMENT; |
| 1082 } | 1253 } |
| 1083 | 1254 |
| 1084 accept(ConstantExpressionVisitor visitor, [context]) { | 1255 accept(ConstantExpressionVisitor visitor, [context]) { |
| 1085 return visitor.visitBoolFromEnvironment(this, context); | 1256 return visitor.visitBoolFromEnvironment(this, context); |
| 1086 } | 1257 } |
| 1087 | 1258 |
| 1088 @override | 1259 @override |
| 1260 void _createStructuredText(StringBuffer sb) { |
| 1261 sb.write('bool.fromEnvironment(name='); |
| 1262 name._createStructuredText(sb); |
| 1263 sb.write(',defaultValue='); |
| 1264 defaultValue._createStructuredText(sb); |
| 1265 sb.write(')'); |
| 1266 } |
| 1267 |
| 1268 @override |
| 1089 ConstantValue evaluate( | 1269 ConstantValue evaluate( |
| 1090 Environment environment, ConstantSystem constantSystem) { | 1270 Environment environment, ConstantSystem constantSystem) { |
| 1091 ConstantValue nameConstantValue = | 1271 ConstantValue nameConstantValue = |
| 1092 name.evaluate(environment, constantSystem); | 1272 name.evaluate(environment, constantSystem); |
| 1093 ConstantValue defaultConstantValue; | 1273 ConstantValue defaultConstantValue; |
| 1094 if (defaultValue != null) { | 1274 if (defaultValue != null) { |
| 1095 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); | 1275 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); |
| 1096 } else { | 1276 } else { |
| 1097 defaultConstantValue = constantSystem.createBool(false); | 1277 defaultConstantValue = constantSystem.createBool(false); |
| 1098 } | 1278 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1129 | 1309 |
| 1130 ConstantExpressionKind get kind { | 1310 ConstantExpressionKind get kind { |
| 1131 return ConstantExpressionKind.INT_FROM_ENVIRONMENT; | 1311 return ConstantExpressionKind.INT_FROM_ENVIRONMENT; |
| 1132 } | 1312 } |
| 1133 | 1313 |
| 1134 accept(ConstantExpressionVisitor visitor, [context]) { | 1314 accept(ConstantExpressionVisitor visitor, [context]) { |
| 1135 return visitor.visitIntFromEnvironment(this, context); | 1315 return visitor.visitIntFromEnvironment(this, context); |
| 1136 } | 1316 } |
| 1137 | 1317 |
| 1138 @override | 1318 @override |
| 1319 void _createStructuredText(StringBuffer sb) { |
| 1320 sb.write('int.fromEnvironment(name='); |
| 1321 name._createStructuredText(sb); |
| 1322 sb.write(',defaultValue='); |
| 1323 defaultValue._createStructuredText(sb); |
| 1324 sb.write(')'); |
| 1325 } |
| 1326 |
| 1327 @override |
| 1139 ConstantValue evaluate( | 1328 ConstantValue evaluate( |
| 1140 Environment environment, ConstantSystem constantSystem) { | 1329 Environment environment, ConstantSystem constantSystem) { |
| 1141 ConstantValue nameConstantValue = | 1330 ConstantValue nameConstantValue = |
| 1142 name.evaluate(environment, constantSystem); | 1331 name.evaluate(environment, constantSystem); |
| 1143 ConstantValue defaultConstantValue; | 1332 ConstantValue defaultConstantValue; |
| 1144 if (defaultValue != null) { | 1333 if (defaultValue != null) { |
| 1145 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); | 1334 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); |
| 1146 } else { | 1335 } else { |
| 1147 defaultConstantValue = constantSystem.createNull(); | 1336 defaultConstantValue = constantSystem.createNull(); |
| 1148 } | 1337 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 | 1370 |
| 1182 ConstantExpressionKind get kind { | 1371 ConstantExpressionKind get kind { |
| 1183 return ConstantExpressionKind.STRING_FROM_ENVIRONMENT; | 1372 return ConstantExpressionKind.STRING_FROM_ENVIRONMENT; |
| 1184 } | 1373 } |
| 1185 | 1374 |
| 1186 accept(ConstantExpressionVisitor visitor, [context]) { | 1375 accept(ConstantExpressionVisitor visitor, [context]) { |
| 1187 return visitor.visitStringFromEnvironment(this, context); | 1376 return visitor.visitStringFromEnvironment(this, context); |
| 1188 } | 1377 } |
| 1189 | 1378 |
| 1190 @override | 1379 @override |
| 1380 void _createStructuredText(StringBuffer sb) { |
| 1381 sb.write('String.fromEnvironment(name='); |
| 1382 name._createStructuredText(sb); |
| 1383 sb.write(',defaultValue='); |
| 1384 defaultValue._createStructuredText(sb); |
| 1385 sb.write(')'); |
| 1386 } |
| 1387 |
| 1388 @override |
| 1191 ConstantValue evaluate( | 1389 ConstantValue evaluate( |
| 1192 Environment environment, ConstantSystem constantSystem) { | 1390 Environment environment, ConstantSystem constantSystem) { |
| 1193 ConstantValue nameConstantValue = | 1391 ConstantValue nameConstantValue = |
| 1194 name.evaluate(environment, constantSystem); | 1392 name.evaluate(environment, constantSystem); |
| 1195 ConstantValue defaultConstantValue; | 1393 ConstantValue defaultConstantValue; |
| 1196 if (defaultValue != null) { | 1394 if (defaultValue != null) { |
| 1197 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); | 1395 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); |
| 1198 } else { | 1396 } else { |
| 1199 defaultConstantValue = constantSystem.createNull(); | 1397 defaultConstantValue = constantSystem.createNull(); |
| 1200 } | 1398 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1224 /// For example `lib.C`. | 1422 /// For example `lib.C`. |
| 1225 class DeferredConstantExpression extends ConstantExpression { | 1423 class DeferredConstantExpression extends ConstantExpression { |
| 1226 final ConstantExpression expression; | 1424 final ConstantExpression expression; |
| 1227 final PrefixElement prefix; | 1425 final PrefixElement prefix; |
| 1228 | 1426 |
| 1229 DeferredConstantExpression(this.expression, this.prefix); | 1427 DeferredConstantExpression(this.expression, this.prefix); |
| 1230 | 1428 |
| 1231 ConstantExpressionKind get kind => ConstantExpressionKind.DEFERRED; | 1429 ConstantExpressionKind get kind => ConstantExpressionKind.DEFERRED; |
| 1232 | 1430 |
| 1233 @override | 1431 @override |
| 1432 void _createStructuredText(StringBuffer sb) { |
| 1433 sb.write('Deferred(prefix=$prefix,expression='); |
| 1434 expression._createStructuredText(sb); |
| 1435 sb.write(')'); |
| 1436 } |
| 1437 |
| 1438 @override |
| 1234 ConstantValue evaluate( | 1439 ConstantValue evaluate( |
| 1235 Environment environment, ConstantSystem constantSystem) { | 1440 Environment environment, ConstantSystem constantSystem) { |
| 1236 return expression.evaluate(environment, constantSystem); | 1441 return expression.evaluate(environment, constantSystem); |
| 1237 } | 1442 } |
| 1238 | 1443 |
| 1239 @override | 1444 @override |
| 1240 int _computeHashCode() { | 1445 int _computeHashCode() { |
| 1241 return 13 * expression.hashCode; | 1446 return 13 * expression.hashCode; |
| 1242 } | 1447 } |
| 1243 | 1448 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1555 visit(exp.name); | 1760 visit(exp.name); |
| 1556 if (exp.defaultValue != null) { | 1761 if (exp.defaultValue != null) { |
| 1557 sb.write(', defaultValue: '); | 1762 sb.write(', defaultValue: '); |
| 1558 visit(exp.defaultValue); | 1763 visit(exp.defaultValue); |
| 1559 } | 1764 } |
| 1560 sb.write(')'); | 1765 sb.write(')'); |
| 1561 } | 1766 } |
| 1562 | 1767 |
| 1563 String toString() => sb.toString(); | 1768 String toString() => sb.toString(); |
| 1564 } | 1769 } |
| OLD | NEW |