| 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 '../elements/resolution_types.dart'; | 10 import '../elements/types.dart'; |
| 11 import '../elements/elements.dart' | 11 import '../elements/entities.dart'; |
| 12 show | |
| 13 ConstructorElement, | |
| 14 FieldElement, | |
| 15 MethodElement, | |
| 16 PrefixElement, | |
| 17 VariableElement; | |
| 18 import '../resolution/operators.dart'; | 12 import '../resolution/operators.dart'; |
| 19 import '../tree/dartstring.dart' show DartString; | 13 import '../tree/dartstring.dart' show DartString; |
| 20 import '../universe/call_structure.dart' show CallStructure; | 14 import '../universe/call_structure.dart' show CallStructure; |
| 15 import 'constructors.dart'; |
| 21 import 'evaluation.dart'; | 16 import 'evaluation.dart'; |
| 22 import 'values.dart'; | 17 import 'values.dart'; |
| 23 | 18 |
| 24 enum ConstantExpressionKind { | 19 enum ConstantExpressionKind { |
| 25 BINARY, | 20 BINARY, |
| 26 BOOL, | 21 BOOL, |
| 27 BOOL_FROM_ENVIRONMENT, | 22 BOOL_FROM_ENVIRONMENT, |
| 28 CONCATENATE, | 23 CONCATENATE, |
| 29 CONDITIONAL, | 24 CONDITIONAL, |
| 30 CONSTRUCTED, | 25 CONSTRUCTED, |
| 31 DEFERRED, | 26 DEFERRED, |
| 32 DOUBLE, | 27 DOUBLE, |
| 33 ERRONEOUS, | 28 ERRONEOUS, |
| 34 FUNCTION, | 29 FUNCTION, |
| 30 FIELD, |
| 35 IDENTICAL, | 31 IDENTICAL, |
| 36 INT, | 32 INT, |
| 37 INT_FROM_ENVIRONMENT, | 33 INT_FROM_ENVIRONMENT, |
| 38 LIST, | 34 LIST, |
| 39 MAP, | 35 MAP, |
| 40 NULL, | 36 NULL, |
| 41 STRING, | 37 STRING, |
| 42 STRING_FROM_ENVIRONMENT, | 38 STRING_FROM_ENVIRONMENT, |
| 43 STRING_LENGTH, | 39 STRING_LENGTH, |
| 44 SYMBOL, | 40 SYMBOL, |
| 45 SYNTHETIC, | 41 SYNTHETIC, |
| 46 TYPE, | 42 TYPE, |
| 47 UNARY, | 43 UNARY, |
| 48 VARIABLE, | 44 LOCAL_VARIABLE, |
| 49 POSITIONAL_REFERENCE, | 45 POSITIONAL_REFERENCE, |
| 50 NAMED_REFERENCE, | 46 NAMED_REFERENCE, |
| 51 } | 47 } |
| 52 | 48 |
| 53 /// An expression that is a compile-time constant. | 49 /// An expression that is a compile-time constant. |
| 54 /// | 50 /// |
| 55 /// Whereas [ConstantValue] represent a compile-time value, a | 51 /// Whereas [ConstantValue] represent a compile-time value, a |
| 56 /// [ConstantExpression] represents an expression for creating a constant. | 52 /// [ConstantExpression] represents an expression for creating a constant. |
| 57 /// | 53 /// |
| 58 /// There is no one-to-one mapping between [ConstantExpression] and | 54 /// There is no one-to-one mapping between [ConstantExpression] and |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 /// Substitute free variables using arguments. | 69 /// Substitute free variables using arguments. |
| 74 ConstantExpression apply(NormalizedArguments arguments) => this; | 70 ConstantExpression apply(NormalizedArguments arguments) => this; |
| 75 | 71 |
| 76 /// Compute the [ConstantValue] for this expression using the [environment] | 72 /// Compute the [ConstantValue] for this expression using the [environment] |
| 77 /// and the [constantSystem]. | 73 /// and the [constantSystem]. |
| 78 ConstantValue evaluate( | 74 ConstantValue evaluate( |
| 79 Environment environment, ConstantSystem constantSystem); | 75 Environment environment, ConstantSystem constantSystem); |
| 80 | 76 |
| 81 /// Returns the type of this constant expression, if it is independent of the | 77 /// Returns the type of this constant expression, if it is independent of the |
| 82 /// environment values. | 78 /// environment values. |
| 83 ResolutionDartType getKnownType(CommonElements commonElements) => null; | 79 DartType getKnownType(CommonElements commonElements) => null; |
| 84 | 80 |
| 85 /// Returns a text string resembling the Dart code creating this constant. | 81 /// Returns a text string resembling the Dart code creating this constant. |
| 86 String toDartText() { | 82 String toDartText() { |
| 87 ConstExpPrinter printer = new ConstExpPrinter(); | 83 ConstExpPrinter printer = new ConstExpPrinter(); |
| 88 accept(printer); | 84 accept(printer); |
| 89 return printer.toString(); | 85 return printer.toString(); |
| 90 } | 86 } |
| 91 | 87 |
| 92 /// Returns a text string showing the structure of this constant. | 88 /// Returns a text string showing the structure of this constant. |
| 93 String toStructuredText() { | 89 String toStructuredText() { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 225 |
| 230 @override | 226 @override |
| 231 int _computeHashCode() => 13 * primitiveValue.hashCode; | 227 int _computeHashCode() => 13 * primitiveValue.hashCode; |
| 232 | 228 |
| 233 @override | 229 @override |
| 234 bool _equals(BoolConstantExpression other) { | 230 bool _equals(BoolConstantExpression other) { |
| 235 return primitiveValue == other.primitiveValue; | 231 return primitiveValue == other.primitiveValue; |
| 236 } | 232 } |
| 237 | 233 |
| 238 @override | 234 @override |
| 239 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 235 InterfaceType getKnownType(CommonElements commonElements) => |
| 240 commonElements.boolType; | 236 commonElements.boolType; |
| 241 } | 237 } |
| 242 | 238 |
| 243 /// Integer literal constant. | 239 /// Integer literal constant. |
| 244 class IntConstantExpression extends PrimitiveConstantExpression { | 240 class IntConstantExpression extends PrimitiveConstantExpression { |
| 245 final int primitiveValue; | 241 final int primitiveValue; |
| 246 | 242 |
| 247 IntConstantExpression(this.primitiveValue); | 243 IntConstantExpression(this.primitiveValue); |
| 248 | 244 |
| 249 ConstantExpressionKind get kind => ConstantExpressionKind.INT; | 245 ConstantExpressionKind get kind => ConstantExpressionKind.INT; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 265 | 261 |
| 266 @override | 262 @override |
| 267 int _computeHashCode() => 17 * primitiveValue.hashCode; | 263 int _computeHashCode() => 17 * primitiveValue.hashCode; |
| 268 | 264 |
| 269 @override | 265 @override |
| 270 bool _equals(IntConstantExpression other) { | 266 bool _equals(IntConstantExpression other) { |
| 271 return primitiveValue == other.primitiveValue; | 267 return primitiveValue == other.primitiveValue; |
| 272 } | 268 } |
| 273 | 269 |
| 274 @override | 270 @override |
| 275 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 271 InterfaceType getKnownType(CommonElements commonElements) => |
| 276 commonElements.intType; | 272 commonElements.intType; |
| 277 } | 273 } |
| 278 | 274 |
| 279 /// Double literal constant. | 275 /// Double literal constant. |
| 280 class DoubleConstantExpression extends PrimitiveConstantExpression { | 276 class DoubleConstantExpression extends PrimitiveConstantExpression { |
| 281 final double primitiveValue; | 277 final double primitiveValue; |
| 282 | 278 |
| 283 DoubleConstantExpression(this.primitiveValue); | 279 DoubleConstantExpression(this.primitiveValue); |
| 284 | 280 |
| 285 ConstantExpressionKind get kind => ConstantExpressionKind.DOUBLE; | 281 ConstantExpressionKind get kind => ConstantExpressionKind.DOUBLE; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 301 | 297 |
| 302 @override | 298 @override |
| 303 int _computeHashCode() => 19 * primitiveValue.hashCode; | 299 int _computeHashCode() => 19 * primitiveValue.hashCode; |
| 304 | 300 |
| 305 @override | 301 @override |
| 306 bool _equals(DoubleConstantExpression other) { | 302 bool _equals(DoubleConstantExpression other) { |
| 307 return primitiveValue == other.primitiveValue; | 303 return primitiveValue == other.primitiveValue; |
| 308 } | 304 } |
| 309 | 305 |
| 310 @override | 306 @override |
| 311 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 307 InterfaceType getKnownType(CommonElements commonElements) => |
| 312 commonElements.doubleType; | 308 commonElements.doubleType; |
| 313 } | 309 } |
| 314 | 310 |
| 315 /// String literal constant. | 311 /// String literal constant. |
| 316 class StringConstantExpression extends PrimitiveConstantExpression { | 312 class StringConstantExpression extends PrimitiveConstantExpression { |
| 317 final String primitiveValue; | 313 final String primitiveValue; |
| 318 | 314 |
| 319 StringConstantExpression(this.primitiveValue); | 315 StringConstantExpression(this.primitiveValue); |
| 320 | 316 |
| 321 ConstantExpressionKind get kind => ConstantExpressionKind.STRING; | 317 ConstantExpressionKind get kind => ConstantExpressionKind.STRING; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 337 | 333 |
| 338 @override | 334 @override |
| 339 int _computeHashCode() => 23 * primitiveValue.hashCode; | 335 int _computeHashCode() => 23 * primitiveValue.hashCode; |
| 340 | 336 |
| 341 @override | 337 @override |
| 342 bool _equals(StringConstantExpression other) { | 338 bool _equals(StringConstantExpression other) { |
| 343 return primitiveValue == other.primitiveValue; | 339 return primitiveValue == other.primitiveValue; |
| 344 } | 340 } |
| 345 | 341 |
| 346 @override | 342 @override |
| 347 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 343 InterfaceType getKnownType(CommonElements commonElements) => |
| 348 commonElements.stringType; | 344 commonElements.stringType; |
| 349 } | 345 } |
| 350 | 346 |
| 351 /// Null literal constant. | 347 /// Null literal constant. |
| 352 class NullConstantExpression extends PrimitiveConstantExpression { | 348 class NullConstantExpression extends PrimitiveConstantExpression { |
| 353 NullConstantExpression(); | 349 NullConstantExpression(); |
| 354 | 350 |
| 355 ConstantExpressionKind get kind => ConstantExpressionKind.NULL; | 351 ConstantExpressionKind get kind => ConstantExpressionKind.NULL; |
| 356 | 352 |
| 357 accept(ConstantExpressionVisitor visitor, [context]) { | 353 accept(ConstantExpressionVisitor visitor, [context]) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 371 | 367 |
| 372 get primitiveValue => null; | 368 get primitiveValue => null; |
| 373 | 369 |
| 374 @override | 370 @override |
| 375 int _computeHashCode() => 29; | 371 int _computeHashCode() => 29; |
| 376 | 372 |
| 377 @override | 373 @override |
| 378 bool _equals(NullConstantExpression other) => true; | 374 bool _equals(NullConstantExpression other) => true; |
| 379 | 375 |
| 380 @override | 376 @override |
| 381 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 377 InterfaceType getKnownType(CommonElements commonElements) => |
| 382 commonElements.nullType; | 378 commonElements.nullType; |
| 383 } | 379 } |
| 384 | 380 |
| 385 /// Literal list constant. | 381 /// Literal list constant. |
| 386 class ListConstantExpression extends ConstantExpression { | 382 class ListConstantExpression extends ConstantExpression { |
| 387 final ResolutionInterfaceType type; | 383 final InterfaceType type; |
| 388 final List<ConstantExpression> values; | 384 final List<ConstantExpression> values; |
| 389 | 385 |
| 390 ListConstantExpression(this.type, this.values); | 386 ListConstantExpression(this.type, this.values); |
| 391 | 387 |
| 392 ConstantExpressionKind get kind => ConstantExpressionKind.LIST; | 388 ConstantExpressionKind get kind => ConstantExpressionKind.LIST; |
| 393 | 389 |
| 394 accept(ConstantExpressionVisitor visitor, [context]) { | 390 accept(ConstantExpressionVisitor visitor, [context]) { |
| 395 return visitor.visitList(this, context); | 391 return visitor.visitList(this, context); |
| 396 } | 392 } |
| 397 | 393 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 bool _equals(ListConstantExpression other) { | 428 bool _equals(ListConstantExpression other) { |
| 433 if (type != other.type) return false; | 429 if (type != other.type) return false; |
| 434 if (values.length != other.values.length) return false; | 430 if (values.length != other.values.length) return false; |
| 435 for (int i = 0; i < values.length; i++) { | 431 for (int i = 0; i < values.length; i++) { |
| 436 if (values[i] != other.values[i]) return false; | 432 if (values[i] != other.values[i]) return false; |
| 437 } | 433 } |
| 438 return true; | 434 return true; |
| 439 } | 435 } |
| 440 | 436 |
| 441 @override | 437 @override |
| 442 ResolutionDartType getKnownType(CommonElements commonElements) => type; | 438 DartType getKnownType(CommonElements commonElements) => type; |
| 443 | 439 |
| 444 @override | 440 @override |
| 445 bool get isImplicit => false; | 441 bool get isImplicit => false; |
| 446 | 442 |
| 447 @override | 443 @override |
| 448 bool get isPotential => values.any((e) => e.isPotential); | 444 bool get isPotential => values.any((e) => e.isPotential); |
| 449 } | 445 } |
| 450 | 446 |
| 451 /// Literal map constant. | 447 /// Literal map constant. |
| 452 class MapConstantExpression extends ConstantExpression { | 448 class MapConstantExpression extends ConstantExpression { |
| 453 final ResolutionInterfaceType type; | 449 final InterfaceType type; |
| 454 final List<ConstantExpression> keys; | 450 final List<ConstantExpression> keys; |
| 455 final List<ConstantExpression> values; | 451 final List<ConstantExpression> values; |
| 456 | 452 |
| 457 MapConstantExpression(this.type, this.keys, this.values); | 453 MapConstantExpression(this.type, this.keys, this.values); |
| 458 | 454 |
| 459 ConstantExpressionKind get kind => ConstantExpressionKind.MAP; | 455 ConstantExpressionKind get kind => ConstantExpressionKind.MAP; |
| 460 | 456 |
| 461 accept(ConstantExpressionVisitor visitor, [context]) { | 457 accept(ConstantExpressionVisitor visitor, [context]) { |
| 462 return visitor.visitMap(this, context); | 458 return visitor.visitMap(this, context); |
| 463 } | 459 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 if (type != other.type) return false; | 507 if (type != other.type) return false; |
| 512 if (values.length != other.values.length) return false; | 508 if (values.length != other.values.length) return false; |
| 513 for (int i = 0; i < values.length; i++) { | 509 for (int i = 0; i < values.length; i++) { |
| 514 if (keys[i] != other.keys[i]) return false; | 510 if (keys[i] != other.keys[i]) return false; |
| 515 if (values[i] != other.values[i]) return false; | 511 if (values[i] != other.values[i]) return false; |
| 516 } | 512 } |
| 517 return true; | 513 return true; |
| 518 } | 514 } |
| 519 | 515 |
| 520 @override | 516 @override |
| 521 ResolutionDartType getKnownType(CommonElements commonElements) => type; | 517 DartType getKnownType(CommonElements commonElements) => type; |
| 522 | 518 |
| 523 @override | 519 @override |
| 524 bool get isImplicit => false; | 520 bool get isImplicit => false; |
| 525 | 521 |
| 526 @override | 522 @override |
| 527 bool get isPotential { | 523 bool get isPotential { |
| 528 return keys.any((e) => e.isPotential) || values.any((e) => e.isPotential); | 524 return keys.any((e) => e.isPotential) || values.any((e) => e.isPotential); |
| 529 } | 525 } |
| 530 } | 526 } |
| 531 | 527 |
| 532 /// Invocation of a const constructor. | 528 /// Invocation of a const constructor. |
| 533 class ConstructedConstantExpression extends ConstantExpression { | 529 class ConstructedConstantExpression extends ConstantExpression { |
| 534 final ResolutionInterfaceType type; | 530 final InterfaceType type; |
| 535 final ConstructorElement target; | 531 final ConstructorEntity target; |
| 536 final CallStructure callStructure; | 532 final CallStructure callStructure; |
| 537 final List<ConstantExpression> arguments; | 533 final List<ConstantExpression> arguments; |
| 538 | 534 |
| 539 ConstructedConstantExpression( | 535 ConstructedConstantExpression( |
| 540 this.type, this.target, this.callStructure, this.arguments) { | 536 this.type, this.target, this.callStructure, this.arguments) { |
| 541 assert(type.element == target.enclosingClass); | 537 assert(type.element == target.enclosingClass); |
| 542 assert(!arguments.contains(null)); | 538 assert(!arguments.contains(null)); |
| 543 } | 539 } |
| 544 | 540 |
| 545 ConstantExpressionKind get kind => ConstantExpressionKind.CONSTRUCTED; | 541 ConstantExpressionKind get kind => ConstantExpressionKind.CONSTRUCTED; |
| 546 | 542 |
| 547 accept(ConstantExpressionVisitor visitor, [context]) { | 543 accept(ConstantExpressionVisitor visitor, [context]) { |
| 548 return visitor.visitConstructed(this, context); | 544 return visitor.visitConstructed(this, context); |
| 549 } | 545 } |
| 550 | 546 |
| 551 @override | 547 @override |
| 552 void _createStructuredText(StringBuffer sb) { | 548 void _createStructuredText(StringBuffer sb) { |
| 553 sb.write('Constructed(type=$type,constructor=$target,' | 549 sb.write('Constructed(type=$type,constructor=$target,' |
| 554 'callStructure=$callStructure,arguments=['); | 550 'callStructure=$callStructure,arguments=['); |
| 555 String delimiter = ''; | 551 String delimiter = ''; |
| 556 for (ConstantExpression value in arguments) { | 552 for (ConstantExpression value in arguments) { |
| 557 sb.write(delimiter); | 553 sb.write(delimiter); |
| 558 value._createStructuredText(sb); | 554 value._createStructuredText(sb); |
| 559 delimiter = ','; | 555 delimiter = ','; |
| 560 } | 556 } |
| 561 sb.write('])'); | 557 sb.write('])'); |
| 562 } | 558 } |
| 563 | 559 |
| 564 Map<FieldElement, ConstantExpression> computeInstanceFields() { | 560 Map<FieldEntity, ConstantExpression> computeInstanceFields( |
| 565 assert(invariant(target, target.constantConstructor != null, | 561 Environment environment) { |
| 562 ConstantConstructor constantConstructor = |
| 563 environment.getConstructorConstant(target); |
| 564 assert(invariant(target, constantConstructor != null, |
| 566 message: "No constant constructor computed for $target.")); | 565 message: "No constant constructor computed for $target.")); |
| 567 return target.constantConstructor | 566 return constantConstructor.computeInstanceFields( |
| 568 .computeInstanceFields(arguments, callStructure); | 567 environment, arguments, callStructure); |
| 569 } | 568 } |
| 570 | 569 |
| 571 ResolutionInterfaceType computeInstanceType() { | 570 InterfaceType computeInstanceType(Environment environment) { |
| 572 return target.constantConstructor.computeInstanceType(type); | 571 return environment |
| 572 .getConstructorConstant(target) |
| 573 .computeInstanceType(environment, type); |
| 573 } | 574 } |
| 574 | 575 |
| 575 ConstructedConstantExpression apply(NormalizedArguments arguments) { | 576 ConstructedConstantExpression apply(NormalizedArguments arguments) { |
| 576 return new ConstructedConstantExpression(type, target, callStructure, | 577 return new ConstructedConstantExpression(type, target, callStructure, |
| 577 this.arguments.map((a) => a.apply(arguments)).toList()); | 578 this.arguments.map((a) => a.apply(arguments)).toList()); |
| 578 } | 579 } |
| 579 | 580 |
| 580 @override | 581 @override |
| 581 ConstantValue evaluate( | 582 ConstantValue evaluate( |
| 582 Environment environment, ConstantSystem constantSystem) { | 583 Environment environment, ConstantSystem constantSystem) { |
| 583 Map<FieldElement, ConstantValue> fieldValues = | 584 Map<FieldEntity, ConstantValue> fieldValues = |
| 584 <FieldElement, ConstantValue>{}; | 585 <FieldEntity, ConstantValue>{}; |
| 585 computeInstanceFields() | 586 computeInstanceFields(environment) |
| 586 .forEach((FieldElement field, ConstantExpression constant) { | 587 .forEach((FieldEntity field, ConstantExpression constant) { |
| 587 fieldValues[field] = constant.evaluate(environment, constantSystem); | 588 fieldValues[field] = constant.evaluate(environment, constantSystem); |
| 588 }); | 589 }); |
| 589 return new ConstructedConstantValue(computeInstanceType(), fieldValues); | 590 return new ConstructedConstantValue( |
| 591 computeInstanceType(environment), fieldValues); |
| 590 } | 592 } |
| 591 | 593 |
| 592 @override | 594 @override |
| 593 int _computeHashCode() { | 595 int _computeHashCode() { |
| 594 int hashCode = | 596 int hashCode = |
| 595 13 * type.hashCode + 17 * target.hashCode + 19 * callStructure.hashCode; | 597 13 * type.hashCode + 17 * target.hashCode + 19 * callStructure.hashCode; |
| 596 for (ConstantExpression value in arguments) { | 598 for (ConstantExpression value in arguments) { |
| 597 hashCode ^= 23 * value.hashCode; | 599 hashCode ^= 23 * value.hashCode; |
| 598 } | 600 } |
| 599 return hashCode; | 601 return hashCode; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 @override | 690 @override |
| 689 bool _equals(ConcatenateConstantExpression other) { | 691 bool _equals(ConcatenateConstantExpression other) { |
| 690 if (expressions.length != other.expressions.length) return false; | 692 if (expressions.length != other.expressions.length) return false; |
| 691 for (int i = 0; i < expressions.length; i++) { | 693 for (int i = 0; i < expressions.length; i++) { |
| 692 if (expressions[i] != other.expressions[i]) return false; | 694 if (expressions[i] != other.expressions[i]) return false; |
| 693 } | 695 } |
| 694 return true; | 696 return true; |
| 695 } | 697 } |
| 696 | 698 |
| 697 @override | 699 @override |
| 698 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 700 InterfaceType getKnownType(CommonElements commonElements) => |
| 699 commonElements.stringType; | 701 commonElements.stringType; |
| 700 | 702 |
| 701 @override | 703 @override |
| 702 bool get isPotential { | 704 bool get isPotential { |
| 703 return expressions.any((e) => e.isPotential); | 705 return expressions.any((e) => e.isPotential); |
| 704 } | 706 } |
| 705 } | 707 } |
| 706 | 708 |
| 707 /// Symbol literal. | 709 /// Symbol literal. |
| 708 class SymbolConstantExpression extends ConstantExpression { | 710 class SymbolConstantExpression extends ConstantExpression { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 729 return name == other.name; | 731 return name == other.name; |
| 730 } | 732 } |
| 731 | 733 |
| 732 @override | 734 @override |
| 733 ConstantValue evaluate( | 735 ConstantValue evaluate( |
| 734 Environment environment, ConstantSystem constantSystem) { | 736 Environment environment, ConstantSystem constantSystem) { |
| 735 return constantSystem.createSymbol(environment.compiler, name); | 737 return constantSystem.createSymbol(environment.compiler, name); |
| 736 } | 738 } |
| 737 | 739 |
| 738 @override | 740 @override |
| 739 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 741 InterfaceType getKnownType(CommonElements commonElements) => |
| 740 commonElements.symbolType; | 742 commonElements.symbolType; |
| 741 } | 743 } |
| 742 | 744 |
| 743 /// Type literal. | 745 /// Type literal. |
| 744 class TypeConstantExpression extends ConstantExpression { | 746 class TypeConstantExpression extends ConstantExpression { |
| 745 /// Either [ResolutionDynamicType] or a raw [GenericType]. | 747 /// Either [DynamicType] or a raw [GenericType]. |
| 746 final ResolutionDartType type; | 748 final DartType type; |
| 749 final String name; |
| 747 | 750 |
| 748 TypeConstantExpression(this.type) { | 751 TypeConstantExpression(this.type, this.name) { |
| 749 assert(type is GenericType || type is ResolutionDynamicType); | 752 assert(type.isInterfaceType || |
| 753 type.isTypedef || |
| 754 type.isFunctionType || |
| 755 type.isDynamic); |
| 750 } | 756 } |
| 751 | 757 |
| 752 ConstantExpressionKind get kind => ConstantExpressionKind.TYPE; | 758 ConstantExpressionKind get kind => ConstantExpressionKind.TYPE; |
| 753 | 759 |
| 754 accept(ConstantExpressionVisitor visitor, [context]) { | 760 accept(ConstantExpressionVisitor visitor, [context]) { |
| 755 return visitor.visitType(this, context); | 761 return visitor.visitType(this, context); |
| 756 } | 762 } |
| 757 | 763 |
| 758 @override | 764 @override |
| 759 void _createStructuredText(StringBuffer sb) { | 765 void _createStructuredText(StringBuffer sb) { |
| 760 sb.write('Type(type=$type)'); | 766 sb.write('Type(type=$type)'); |
| 761 } | 767 } |
| 762 | 768 |
| 763 @override | 769 @override |
| 764 ConstantValue evaluate( | 770 ConstantValue evaluate( |
| 765 Environment environment, ConstantSystem constantSystem) { | 771 Environment environment, ConstantSystem constantSystem) { |
| 766 return constantSystem.createType(environment.compiler, type); | 772 return constantSystem.createType(environment.compiler, type); |
| 767 } | 773 } |
| 768 | 774 |
| 769 @override | 775 @override |
| 770 int _computeHashCode() => 13 * type.hashCode; | 776 int _computeHashCode() => 13 * type.hashCode; |
| 771 | 777 |
| 772 @override | 778 @override |
| 773 bool _equals(TypeConstantExpression other) { | 779 bool _equals(TypeConstantExpression other) { |
| 774 return type == other.type; | 780 return type == other.type; |
| 775 } | 781 } |
| 776 | 782 |
| 777 @override | 783 @override |
| 778 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 784 InterfaceType getKnownType(CommonElements commonElements) => |
| 779 commonElements.typeType; | 785 commonElements.typeType; |
| 780 } | 786 } |
| 781 | 787 |
| 782 /// Reference to a constant local, top-level, or static variable. | 788 /// Reference to a constant top-level or static field. |
| 783 class VariableConstantExpression extends ConstantExpression { | 789 class FieldConstantExpression extends ConstantExpression { |
| 784 final VariableElement element; | 790 final FieldEntity element; |
| 785 | 791 |
| 786 VariableConstantExpression(this.element); | 792 FieldConstantExpression(this.element); |
| 787 | 793 |
| 788 ConstantExpressionKind get kind => ConstantExpressionKind.VARIABLE; | 794 ConstantExpressionKind get kind => ConstantExpressionKind.FIELD; |
| 789 | 795 |
| 790 accept(ConstantExpressionVisitor visitor, [context]) { | 796 accept(ConstantExpressionVisitor visitor, [context]) { |
| 791 return visitor.visitVariable(this, context); | 797 return visitor.visitField(this, context); |
| 792 } | 798 } |
| 793 | 799 |
| 794 @override | 800 @override |
| 795 void _createStructuredText(StringBuffer sb) { | 801 void _createStructuredText(StringBuffer sb) { |
| 796 sb.write('Variable(element=$element)'); | 802 sb.write('Field(element=$element)'); |
| 797 } | 803 } |
| 798 | 804 |
| 799 @override | 805 @override |
| 800 ConstantValue evaluate( | 806 ConstantValue evaluate( |
| 801 Environment environment, ConstantSystem constantSystem) { | 807 Environment environment, ConstantSystem constantSystem) { |
| 802 return element.constant.evaluate(environment, constantSystem); | 808 ConstantExpression constant = environment.getFieldConstant(element); |
| 809 return constant.evaluate(environment, constantSystem); |
| 803 } | 810 } |
| 804 | 811 |
| 805 @override | 812 @override |
| 806 int _computeHashCode() => 13 * element.hashCode; | 813 int _computeHashCode() => 13 * element.hashCode; |
| 807 | 814 |
| 808 @override | 815 @override |
| 809 bool _equals(VariableConstantExpression other) { | 816 bool _equals(FieldConstantExpression other) { |
| 817 return element == other.element; |
| 818 } |
| 819 } |
| 820 |
| 821 /// Reference to a constant local variable. |
| 822 class LocalVariableConstantExpression extends ConstantExpression { |
| 823 final Local element; |
| 824 |
| 825 LocalVariableConstantExpression(this.element); |
| 826 |
| 827 ConstantExpressionKind get kind => ConstantExpressionKind.LOCAL_VARIABLE; |
| 828 |
| 829 accept(ConstantExpressionVisitor visitor, [context]) { |
| 830 return visitor.visitLocalVariable(this, context); |
| 831 } |
| 832 |
| 833 @override |
| 834 void _createStructuredText(StringBuffer sb) { |
| 835 sb.write('LocalVariable(element=$element)'); |
| 836 } |
| 837 |
| 838 @override |
| 839 ConstantValue evaluate( |
| 840 Environment environment, ConstantSystem constantSystem) { |
| 841 ConstantExpression constant = environment.getLocalConstant(element); |
| 842 return constant.evaluate(environment, constantSystem); |
| 843 } |
| 844 |
| 845 @override |
| 846 int _computeHashCode() => 13 * element.hashCode; |
| 847 |
| 848 @override |
| 849 bool _equals(LocalVariableConstantExpression other) { |
| 810 return element == other.element; | 850 return element == other.element; |
| 811 } | 851 } |
| 812 } | 852 } |
| 813 | 853 |
| 814 /// Reference to a top-level or static function. | 854 /// Reference to a top-level or static function. |
| 815 class FunctionConstantExpression extends ConstantExpression { | 855 class FunctionConstantExpression extends ConstantExpression { |
| 816 final MethodElement element; | 856 final FunctionEntity element; |
| 857 final FunctionType type; |
| 817 | 858 |
| 818 FunctionConstantExpression(this.element); | 859 FunctionConstantExpression(this.element, this.type); |
| 819 | 860 |
| 820 ConstantExpressionKind get kind => ConstantExpressionKind.FUNCTION; | 861 ConstantExpressionKind get kind => ConstantExpressionKind.FUNCTION; |
| 821 | 862 |
| 822 accept(ConstantExpressionVisitor visitor, [context]) { | 863 accept(ConstantExpressionVisitor visitor, [context]) { |
| 823 return visitor.visitFunction(this, context); | 864 return visitor.visitFunction(this, context); |
| 824 } | 865 } |
| 825 | 866 |
| 826 @override | 867 @override |
| 827 void _createStructuredText(StringBuffer sb) { | 868 void _createStructuredText(StringBuffer sb) { |
| 828 sb.write('Function(element=$element)'); | 869 sb.write('Function(element=$element)'); |
| 829 } | 870 } |
| 830 | 871 |
| 831 @override | 872 @override |
| 832 ConstantValue evaluate( | 873 ConstantValue evaluate( |
| 833 Environment environment, ConstantSystem constantSystem) { | 874 Environment environment, ConstantSystem constantSystem) { |
| 834 return new FunctionConstantValue(element, element.type); | 875 return new FunctionConstantValue(element, type); |
| 835 } | 876 } |
| 836 | 877 |
| 837 @override | 878 @override |
| 838 int _computeHashCode() => 13 * element.hashCode; | 879 int _computeHashCode() => 13 * element.hashCode; |
| 839 | 880 |
| 840 @override | 881 @override |
| 841 bool _equals(FunctionConstantExpression other) { | 882 bool _equals(FunctionConstantExpression other) { |
| 842 return element == other.element; | 883 return element == other.element; |
| 843 } | 884 } |
| 844 | 885 |
| 845 @override | 886 @override |
| 846 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 887 InterfaceType getKnownType(CommonElements commonElements) => |
| 847 commonElements.functionType; | 888 commonElements.functionType; |
| 848 } | 889 } |
| 849 | 890 |
| 850 /// A constant binary expression like `a * b`. | 891 /// A constant binary expression like `a * b`. |
| 851 class BinaryConstantExpression extends ConstantExpression { | 892 class BinaryConstantExpression extends ConstantExpression { |
| 852 final ConstantExpression left; | 893 final ConstantExpression left; |
| 853 final BinaryOperator operator; | 894 final BinaryOperator operator; |
| 854 final ConstantExpression right; | 895 final ConstantExpression right; |
| 855 | 896 |
| 856 BinaryConstantExpression(this.left, this.operator, this.right) { | 897 BinaryConstantExpression(this.left, this.operator, this.right) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 887 .lookupBinary(operator) | 928 .lookupBinary(operator) |
| 888 .fold(leftValue, rightValue); | 929 .fold(leftValue, rightValue); |
| 889 } | 930 } |
| 890 } | 931 } |
| 891 | 932 |
| 892 ConstantExpression apply(NormalizedArguments arguments) { | 933 ConstantExpression apply(NormalizedArguments arguments) { |
| 893 return new BinaryConstantExpression( | 934 return new BinaryConstantExpression( |
| 894 left.apply(arguments), operator, right.apply(arguments)); | 935 left.apply(arguments), operator, right.apply(arguments)); |
| 895 } | 936 } |
| 896 | 937 |
| 897 ResolutionInterfaceType getKnownType(CommonElements commonElements) { | 938 InterfaceType getKnownType(CommonElements commonElements) { |
| 898 ResolutionDartType knownLeftType = left.getKnownType(commonElements); | 939 DartType knownLeftType = left.getKnownType(commonElements); |
| 899 ResolutionDartType knownRightType = right.getKnownType(commonElements); | 940 DartType knownRightType = right.getKnownType(commonElements); |
| 900 switch (operator.kind) { | 941 switch (operator.kind) { |
| 901 case BinaryOperatorKind.EQ: | 942 case BinaryOperatorKind.EQ: |
| 902 case BinaryOperatorKind.NOT_EQ: | 943 case BinaryOperatorKind.NOT_EQ: |
| 903 case BinaryOperatorKind.LOGICAL_AND: | 944 case BinaryOperatorKind.LOGICAL_AND: |
| 904 case BinaryOperatorKind.LOGICAL_OR: | 945 case BinaryOperatorKind.LOGICAL_OR: |
| 905 case BinaryOperatorKind.GT: | 946 case BinaryOperatorKind.GT: |
| 906 case BinaryOperatorKind.LT: | 947 case BinaryOperatorKind.LT: |
| 907 case BinaryOperatorKind.GTEQ: | 948 case BinaryOperatorKind.GTEQ: |
| 908 case BinaryOperatorKind.LTEQ: | 949 case BinaryOperatorKind.LTEQ: |
| 909 return commonElements.boolType; | 950 return commonElements.boolType; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 int _computeHashCode() { | 1070 int _computeHashCode() { |
| 1030 return 17 * left.hashCode + 19 * right.hashCode; | 1071 return 17 * left.hashCode + 19 * right.hashCode; |
| 1031 } | 1072 } |
| 1032 | 1073 |
| 1033 @override | 1074 @override |
| 1034 bool _equals(IdenticalConstantExpression other) { | 1075 bool _equals(IdenticalConstantExpression other) { |
| 1035 return left == other.left && right == other.right; | 1076 return left == other.left && right == other.right; |
| 1036 } | 1077 } |
| 1037 | 1078 |
| 1038 @override | 1079 @override |
| 1039 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 1080 InterfaceType getKnownType(CommonElements commonElements) => |
| 1040 commonElements.boolType; | 1081 commonElements.boolType; |
| 1041 | 1082 |
| 1042 @override | 1083 @override |
| 1043 bool get isPotential { | 1084 bool get isPotential { |
| 1044 return left.isPotential || right.isPotential; | 1085 return left.isPotential || right.isPotential; |
| 1045 } | 1086 } |
| 1046 } | 1087 } |
| 1047 | 1088 |
| 1048 /// A unary constant expression like `-a`. | 1089 /// A unary constant expression like `-a`. |
| 1049 class UnaryConstantExpression extends ConstantExpression { | 1090 class UnaryConstantExpression extends ConstantExpression { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 int _computeHashCode() { | 1126 int _computeHashCode() { |
| 1086 return 13 * operator.hashCode + 17 * expression.hashCode; | 1127 return 13 * operator.hashCode + 17 * expression.hashCode; |
| 1087 } | 1128 } |
| 1088 | 1129 |
| 1089 @override | 1130 @override |
| 1090 bool _equals(UnaryConstantExpression other) { | 1131 bool _equals(UnaryConstantExpression other) { |
| 1091 return operator == other.operator && expression == other.expression; | 1132 return operator == other.operator && expression == other.expression; |
| 1092 } | 1133 } |
| 1093 | 1134 |
| 1094 @override | 1135 @override |
| 1095 ResolutionDartType getKnownType(CommonElements commonElements) { | 1136 DartType getKnownType(CommonElements commonElements) { |
| 1096 return expression.getKnownType(commonElements); | 1137 return expression.getKnownType(commonElements); |
| 1097 } | 1138 } |
| 1098 | 1139 |
| 1099 @override | 1140 @override |
| 1100 bool get isPotential { | 1141 bool get isPotential { |
| 1101 return expression.isPotential; | 1142 return expression.isPotential; |
| 1102 } | 1143 } |
| 1103 | 1144 |
| 1104 static const Map<UnaryOperatorKind, int> PRECEDENCE_MAP = const { | 1145 static const Map<UnaryOperatorKind, int> PRECEDENCE_MAP = const { |
| 1105 UnaryOperatorKind.NOT: 14, | 1146 UnaryOperatorKind.NOT: 14, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 int _computeHashCode() { | 1189 int _computeHashCode() { |
| 1149 return 23 * expression.hashCode; | 1190 return 23 * expression.hashCode; |
| 1150 } | 1191 } |
| 1151 | 1192 |
| 1152 @override | 1193 @override |
| 1153 bool _equals(StringLengthConstantExpression other) { | 1194 bool _equals(StringLengthConstantExpression other) { |
| 1154 return expression == other.expression; | 1195 return expression == other.expression; |
| 1155 } | 1196 } |
| 1156 | 1197 |
| 1157 @override | 1198 @override |
| 1158 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 1199 InterfaceType getKnownType(CommonElements commonElements) => |
| 1159 commonElements.intType; | 1200 commonElements.intType; |
| 1160 | 1201 |
| 1161 @override | 1202 @override |
| 1162 bool get isPotential { | 1203 bool get isPotential { |
| 1163 return expression.isPotential; | 1204 return expression.isPotential; |
| 1164 } | 1205 } |
| 1165 } | 1206 } |
| 1166 | 1207 |
| 1167 /// A constant conditional expression like `a ? b : c`. | 1208 /// A constant conditional expression like `a ? b : c`. |
| 1168 class ConditionalConstantExpression extends ConstantExpression { | 1209 class ConditionalConstantExpression extends ConstantExpression { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 if (conditionValue.isTrue) { | 1261 if (conditionValue.isTrue) { |
| 1221 return trueValue; | 1262 return trueValue; |
| 1222 } else if (conditionValue.isFalse) { | 1263 } else if (conditionValue.isFalse) { |
| 1223 return falseValue; | 1264 return falseValue; |
| 1224 } else { | 1265 } else { |
| 1225 return new NonConstantValue(); | 1266 return new NonConstantValue(); |
| 1226 } | 1267 } |
| 1227 } | 1268 } |
| 1228 | 1269 |
| 1229 @override | 1270 @override |
| 1230 ResolutionDartType getKnownType(CommonElements commonElements) { | 1271 DartType getKnownType(CommonElements commonElements) { |
| 1231 ResolutionDartType trueType = trueExp.getKnownType(commonElements); | 1272 DartType trueType = trueExp.getKnownType(commonElements); |
| 1232 ResolutionDartType falseType = falseExp.getKnownType(commonElements); | 1273 DartType falseType = falseExp.getKnownType(commonElements); |
| 1233 if (trueType == falseType) { | 1274 if (trueType == falseType) { |
| 1234 return trueType; | 1275 return trueType; |
| 1235 } | 1276 } |
| 1236 return null; | 1277 return null; |
| 1237 } | 1278 } |
| 1238 | 1279 |
| 1239 @override | 1280 @override |
| 1240 bool get isPotential { | 1281 bool get isPotential { |
| 1241 return condition.isPotential || trueExp.isPotential || falseExp.isPotential; | 1282 return condition.isPotential || trueExp.isPotential || falseExp.isPotential; |
| 1242 } | 1283 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 return defaultConstantValue; | 1442 return defaultConstantValue; |
| 1402 } | 1443 } |
| 1403 } | 1444 } |
| 1404 | 1445 |
| 1405 ConstantExpression apply(NormalizedArguments arguments) { | 1446 ConstantExpression apply(NormalizedArguments arguments) { |
| 1406 return new BoolFromEnvironmentConstantExpression(name.apply(arguments), | 1447 return new BoolFromEnvironmentConstantExpression(name.apply(arguments), |
| 1407 defaultValue != null ? defaultValue.apply(arguments) : null); | 1448 defaultValue != null ? defaultValue.apply(arguments) : null); |
| 1408 } | 1449 } |
| 1409 | 1450 |
| 1410 @override | 1451 @override |
| 1411 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 1452 InterfaceType getKnownType(CommonElements commonElements) => |
| 1412 commonElements.boolType; | 1453 commonElements.boolType; |
| 1413 } | 1454 } |
| 1414 | 1455 |
| 1415 /// A `const int.fromEnvironment` constant. | 1456 /// A `const int.fromEnvironment` constant. |
| 1416 class IntFromEnvironmentConstantExpression | 1457 class IntFromEnvironmentConstantExpression |
| 1417 extends FromEnvironmentConstantExpression { | 1458 extends FromEnvironmentConstantExpression { |
| 1418 IntFromEnvironmentConstantExpression( | 1459 IntFromEnvironmentConstantExpression( |
| 1419 ConstantExpression name, ConstantExpression defaultValue) | 1460 ConstantExpression name, ConstantExpression defaultValue) |
| 1420 : super(name, defaultValue); | 1461 : super(name, defaultValue); |
| 1421 | 1462 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 return constantSystem.createInt(value); | 1508 return constantSystem.createInt(value); |
| 1468 } | 1509 } |
| 1469 } | 1510 } |
| 1470 | 1511 |
| 1471 ConstantExpression apply(NormalizedArguments arguments) { | 1512 ConstantExpression apply(NormalizedArguments arguments) { |
| 1472 return new IntFromEnvironmentConstantExpression(name.apply(arguments), | 1513 return new IntFromEnvironmentConstantExpression(name.apply(arguments), |
| 1473 defaultValue != null ? defaultValue.apply(arguments) : null); | 1514 defaultValue != null ? defaultValue.apply(arguments) : null); |
| 1474 } | 1515 } |
| 1475 | 1516 |
| 1476 @override | 1517 @override |
| 1477 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 1518 InterfaceType getKnownType(CommonElements commonElements) => |
| 1478 commonElements.intType; | 1519 commonElements.intType; |
| 1479 } | 1520 } |
| 1480 | 1521 |
| 1481 /// A `const String.fromEnvironment` constant. | 1522 /// A `const String.fromEnvironment` constant. |
| 1482 class StringFromEnvironmentConstantExpression | 1523 class StringFromEnvironmentConstantExpression |
| 1483 extends FromEnvironmentConstantExpression { | 1524 extends FromEnvironmentConstantExpression { |
| 1484 StringFromEnvironmentConstantExpression( | 1525 StringFromEnvironmentConstantExpression( |
| 1485 ConstantExpression name, ConstantExpression defaultValue) | 1526 ConstantExpression name, ConstantExpression defaultValue) |
| 1486 : super(name, defaultValue); | 1527 : super(name, defaultValue); |
| 1487 | 1528 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 return constantSystem.createString(new DartString.literal(text)); | 1570 return constantSystem.createString(new DartString.literal(text)); |
| 1530 } | 1571 } |
| 1531 } | 1572 } |
| 1532 | 1573 |
| 1533 ConstantExpression apply(NormalizedArguments arguments) { | 1574 ConstantExpression apply(NormalizedArguments arguments) { |
| 1534 return new StringFromEnvironmentConstantExpression(name.apply(arguments), | 1575 return new StringFromEnvironmentConstantExpression(name.apply(arguments), |
| 1535 defaultValue != null ? defaultValue.apply(arguments) : null); | 1576 defaultValue != null ? defaultValue.apply(arguments) : null); |
| 1536 } | 1577 } |
| 1537 | 1578 |
| 1538 @override | 1579 @override |
| 1539 ResolutionInterfaceType getKnownType(CommonElements commonElements) => | 1580 InterfaceType getKnownType(CommonElements commonElements) => |
| 1540 commonElements.stringType; | 1581 commonElements.stringType; |
| 1541 } | 1582 } |
| 1542 | 1583 |
| 1543 /// A constant expression referenced with a deferred prefix. | 1584 /// A constant expression referenced with a deferred prefix. |
| 1544 /// For example `lib.C`. | 1585 /// For example `lib.C`. |
| 1545 class DeferredConstantExpression extends ConstantExpression { | 1586 class DeferredConstantExpression extends ConstantExpression { |
| 1546 final ConstantExpression expression; | 1587 final ConstantExpression expression; |
| 1547 final PrefixElement prefix; | 1588 final Entity prefix; |
| 1548 | 1589 |
| 1549 DeferredConstantExpression(this.expression, this.prefix); | 1590 DeferredConstantExpression(this.expression, this.prefix); |
| 1550 | 1591 |
| 1551 ConstantExpressionKind get kind => ConstantExpressionKind.DEFERRED; | 1592 ConstantExpressionKind get kind => ConstantExpressionKind.DEFERRED; |
| 1552 | 1593 |
| 1553 @override | 1594 @override |
| 1554 void _createStructuredText(StringBuffer sb) { | 1595 void _createStructuredText(StringBuffer sb) { |
| 1555 sb.write('Deferred(prefix=$prefix,expression='); | 1596 sb.write('Deferred(prefix=$prefix,expression='); |
| 1556 expression._createStructuredText(sb); | 1597 expression._createStructuredText(sb); |
| 1557 sb.write(')'); | 1598 sb.write(')'); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 R visitInt(IntConstantExpression exp, A context); | 1641 R visitInt(IntConstantExpression exp, A context); |
| 1601 R visitDouble(DoubleConstantExpression exp, A context); | 1642 R visitDouble(DoubleConstantExpression exp, A context); |
| 1602 R visitString(StringConstantExpression exp, A context); | 1643 R visitString(StringConstantExpression exp, A context); |
| 1603 R visitNull(NullConstantExpression exp, A context); | 1644 R visitNull(NullConstantExpression exp, A context); |
| 1604 R visitList(ListConstantExpression exp, A context); | 1645 R visitList(ListConstantExpression exp, A context); |
| 1605 R visitMap(MapConstantExpression exp, A context); | 1646 R visitMap(MapConstantExpression exp, A context); |
| 1606 R visitConstructed(ConstructedConstantExpression exp, A context); | 1647 R visitConstructed(ConstructedConstantExpression exp, A context); |
| 1607 R visitConcatenate(ConcatenateConstantExpression exp, A context); | 1648 R visitConcatenate(ConcatenateConstantExpression exp, A context); |
| 1608 R visitSymbol(SymbolConstantExpression exp, A context); | 1649 R visitSymbol(SymbolConstantExpression exp, A context); |
| 1609 R visitType(TypeConstantExpression exp, A context); | 1650 R visitType(TypeConstantExpression exp, A context); |
| 1610 R visitVariable(VariableConstantExpression exp, A context); | 1651 R visitLocalVariable(LocalVariableConstantExpression exp, A context); |
| 1652 R visitField(FieldConstantExpression exp, A context); |
| 1611 R visitFunction(FunctionConstantExpression exp, A context); | 1653 R visitFunction(FunctionConstantExpression exp, A context); |
| 1612 R visitBinary(BinaryConstantExpression exp, A context); | 1654 R visitBinary(BinaryConstantExpression exp, A context); |
| 1613 R visitIdentical(IdenticalConstantExpression exp, A context); | 1655 R visitIdentical(IdenticalConstantExpression exp, A context); |
| 1614 R visitUnary(UnaryConstantExpression exp, A context); | 1656 R visitUnary(UnaryConstantExpression exp, A context); |
| 1615 R visitStringLength(StringLengthConstantExpression exp, A context); | 1657 R visitStringLength(StringLengthConstantExpression exp, A context); |
| 1616 R visitConditional(ConditionalConstantExpression exp, A context); | 1658 R visitConditional(ConditionalConstantExpression exp, A context); |
| 1617 R visitBoolFromEnvironment( | 1659 R visitBoolFromEnvironment( |
| 1618 BoolFromEnvironmentConstantExpression exp, A context); | 1660 BoolFromEnvironmentConstantExpression exp, A context); |
| 1619 R visitIntFromEnvironment( | 1661 R visitIntFromEnvironment( |
| 1620 IntFromEnvironmentConstantExpression exp, A context); | 1662 IntFromEnvironmentConstantExpression exp, A context); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1634 if (child.precedence < parent.precedence || | 1676 if (child.precedence < parent.precedence || |
| 1635 !leftAssociative && child.precedence == parent.precedence) { | 1677 !leftAssociative && child.precedence == parent.precedence) { |
| 1636 sb.write('('); | 1678 sb.write('('); |
| 1637 child.accept(this); | 1679 child.accept(this); |
| 1638 sb.write(')'); | 1680 sb.write(')'); |
| 1639 } else { | 1681 } else { |
| 1640 child.accept(this); | 1682 child.accept(this); |
| 1641 } | 1683 } |
| 1642 } | 1684 } |
| 1643 | 1685 |
| 1644 void writeTypeArguments(ResolutionInterfaceType type) { | 1686 void writeTypeArguments(InterfaceType type) { |
| 1645 if (type.treatAsRaw) return; | 1687 if (type.treatAsRaw) return; |
| 1646 sb.write('<'); | 1688 sb.write('<'); |
| 1647 bool needsComma = false; | 1689 bool needsComma = false; |
| 1648 for (ResolutionDartType value in type.typeArguments) { | 1690 for (DartType value in type.typeArguments) { |
| 1649 if (needsComma) { | 1691 if (needsComma) { |
| 1650 sb.write(', '); | 1692 sb.write(', '); |
| 1651 } | 1693 } |
| 1652 sb.write(value); | 1694 sb.write(value); |
| 1653 needsComma = true; | 1695 needsComma = true; |
| 1654 } | 1696 } |
| 1655 sb.write('>'); | 1697 sb.write('>'); |
| 1656 } | 1698 } |
| 1657 | 1699 |
| 1658 @override | 1700 @override |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 } | 1814 } |
| 1773 | 1815 |
| 1774 @override | 1816 @override |
| 1775 void visitSymbol(SymbolConstantExpression exp, [_]) { | 1817 void visitSymbol(SymbolConstantExpression exp, [_]) { |
| 1776 sb.write('#'); | 1818 sb.write('#'); |
| 1777 sb.write(exp.name); | 1819 sb.write(exp.name); |
| 1778 } | 1820 } |
| 1779 | 1821 |
| 1780 @override | 1822 @override |
| 1781 void visitType(TypeConstantExpression exp, [_]) { | 1823 void visitType(TypeConstantExpression exp, [_]) { |
| 1782 sb.write(exp.type.name); | 1824 sb.write(exp.name); |
| 1783 } | 1825 } |
| 1784 | 1826 |
| 1785 @override | 1827 @override |
| 1786 void visitVariable(VariableConstantExpression exp, [_]) { | 1828 void visitField(FieldConstantExpression exp, [_]) { |
| 1787 if (exp.element.isStatic) { | 1829 if (exp.element.isStatic) { |
| 1788 sb.write(exp.element.enclosingClass.name); | 1830 sb.write(exp.element.enclosingClass.name); |
| 1789 sb.write('.'); | 1831 sb.write('.'); |
| 1790 } | 1832 } |
| 1791 sb.write(exp.element.name); | 1833 sb.write(exp.element.name); |
| 1792 } | 1834 } |
| 1793 | 1835 |
| 1794 @override | 1836 @override |
| 1837 void visitLocalVariable(LocalVariableConstantExpression exp, [_]) { |
| 1838 sb.write(exp.element.name); |
| 1839 } |
| 1840 |
| 1841 @override |
| 1795 void visitFunction(FunctionConstantExpression exp, [_]) { | 1842 void visitFunction(FunctionConstantExpression exp, [_]) { |
| 1796 if (exp.element.isStatic) { | 1843 if (exp.element.isStatic) { |
| 1797 sb.write(exp.element.enclosingClass.name); | 1844 sb.write(exp.element.enclosingClass.name); |
| 1798 sb.write('.'); | 1845 sb.write('.'); |
| 1799 } | 1846 } |
| 1800 sb.write(exp.element.name); | 1847 sb.write(exp.element.name); |
| 1801 } | 1848 } |
| 1802 | 1849 |
| 1803 @override | 1850 @override |
| 1804 void visitBinary(BinaryConstantExpression exp, [_]) { | 1851 void visitBinary(BinaryConstantExpression exp, [_]) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 visit(exp.name); | 1935 visit(exp.name); |
| 1889 if (exp.defaultValue != null) { | 1936 if (exp.defaultValue != null) { |
| 1890 sb.write(', defaultValue: '); | 1937 sb.write(', defaultValue: '); |
| 1891 visit(exp.defaultValue); | 1938 visit(exp.defaultValue); |
| 1892 } | 1939 } |
| 1893 sb.write(')'); | 1940 sb.write(')'); |
| 1894 } | 1941 } |
| 1895 | 1942 |
| 1896 String toString() => sb.toString(); | 1943 String toString() => sb.toString(); |
| 1897 } | 1944 } |
| OLD | NEW |