Chromium Code Reviews| 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 /** | 5 /** |
| 6 * The implementation of the class [DartObject]. | 6 * The implementation of the class [DartObject]. |
| 7 */ | 7 */ |
| 8 library analyzer.src.dart.constant.value; | 8 library analyzer.src.dart.constant.value; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| 11 | 11 |
| 12 import 'package:analyzer/dart/constant/value.dart'; | 12 import 'package:analyzer/dart/constant/value.dart'; |
| 13 import 'package:analyzer/dart/element/element.dart'; | 13 import 'package:analyzer/dart/element/element.dart'; |
| 14 import 'package:analyzer/dart/element/type.dart'; | 14 import 'package:analyzer/dart/element/type.dart'; |
| 15 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
| 16 import 'package:analyzer/src/generated/java_core.dart'; | |
| 17 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 16 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 18 import 'package:analyzer/src/generated/utilities_general.dart'; | 17 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 19 | 18 |
| 20 /** | 19 /** |
| 21 * The state of an object representing a boolean value. | 20 * The state of an object representing a boolean value. |
| 22 */ | 21 */ |
| 23 class BoolState extends InstanceState { | 22 class BoolState extends InstanceState { |
| 24 /** | 23 /** |
| 25 * An instance representing the boolean value 'false'. | 24 * An instance representing the boolean value 'false'. |
| 26 */ | 25 */ |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 if (result is IntState) { | 232 if (result is IntState) { |
| 234 return new DartObjectImpl(typeProvider.intType, result); | 233 return new DartObjectImpl(typeProvider.intType, result); |
| 235 } else if (result is DoubleState) { | 234 } else if (result is DoubleState) { |
| 236 return new DartObjectImpl(typeProvider.doubleType, result); | 235 return new DartObjectImpl(typeProvider.doubleType, result); |
| 237 } else if (result is NumState) { | 236 } else if (result is NumState) { |
| 238 return new DartObjectImpl(typeProvider.numType, result); | 237 return new DartObjectImpl(typeProvider.numType, result); |
| 239 } else if (result is StringState) { | 238 } else if (result is StringState) { |
| 240 return new DartObjectImpl(typeProvider.stringType, result); | 239 return new DartObjectImpl(typeProvider.stringType, result); |
| 241 } | 240 } |
| 242 // We should never get here. | 241 // We should never get here. |
| 243 throw new IllegalStateException("add returned a ${result.runtimeType}"); | 242 throw new StateError("add returned a ${result.runtimeType}"); |
| 244 } | 243 } |
| 245 | 244 |
| 246 /** | 245 /** |
| 247 * Return the result of invoking the '&' operator on this object with the | 246 * Return the result of invoking the '&' operator on this object with the |
| 248 * [rightOperand]. The [typeProvider] is the type provider used to find known | 247 * [rightOperand]. The [typeProvider] is the type provider used to find known |
| 249 * types. | 248 * types. |
| 250 * | 249 * |
| 251 * Throws an [EvaluationException] if the operator is not appropriate for an | 250 * Throws an [EvaluationException] if the operator is not appropriate for an |
| 252 * object of this kind. | 251 * object of this kind. |
| 253 */ | 252 */ |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 TypeProvider typeProvider, DartObjectImpl rightOperand) { | 331 TypeProvider typeProvider, DartObjectImpl rightOperand) { |
| 333 InstanceState result = _state.divide(rightOperand._state); | 332 InstanceState result = _state.divide(rightOperand._state); |
| 334 if (result is IntState) { | 333 if (result is IntState) { |
| 335 return new DartObjectImpl(typeProvider.intType, result); | 334 return new DartObjectImpl(typeProvider.intType, result); |
| 336 } else if (result is DoubleState) { | 335 } else if (result is DoubleState) { |
| 337 return new DartObjectImpl(typeProvider.doubleType, result); | 336 return new DartObjectImpl(typeProvider.doubleType, result); |
| 338 } else if (result is NumState) { | 337 } else if (result is NumState) { |
| 339 return new DartObjectImpl(typeProvider.numType, result); | 338 return new DartObjectImpl(typeProvider.numType, result); |
| 340 } | 339 } |
| 341 // We should never get here. | 340 // We should never get here. |
| 342 throw new IllegalStateException("divide returned a ${result.runtimeType}"); | 341 throw new StateError("divide returned a ${result.runtimeType}"); |
| 343 } | 342 } |
| 344 | 343 |
| 345 /** | 344 /** |
| 346 * Return the result of invoking the '==' operator on this object with the | 345 * Return the result of invoking the '==' operator on this object with the |
| 347 * [rightOperand]. The [typeProvider] is the type provider used to find known | 346 * [rightOperand]. The [typeProvider] is the type provider used to find known |
| 348 * types. | 347 * types. |
| 349 * | 348 * |
| 350 * Throws an [EvaluationException] if the operator is not appropriate for an | 349 * Throws an [EvaluationException] if the operator is not appropriate for an |
| 351 * object of this kind. | 350 * object of this kind. |
| 352 */ | 351 */ |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 DartObjectImpl minus(TypeProvider typeProvider, DartObjectImpl rightOperand) { | 500 DartObjectImpl minus(TypeProvider typeProvider, DartObjectImpl rightOperand) { |
| 502 InstanceState result = _state.minus(rightOperand._state); | 501 InstanceState result = _state.minus(rightOperand._state); |
| 503 if (result is IntState) { | 502 if (result is IntState) { |
| 504 return new DartObjectImpl(typeProvider.intType, result); | 503 return new DartObjectImpl(typeProvider.intType, result); |
| 505 } else if (result is DoubleState) { | 504 } else if (result is DoubleState) { |
| 506 return new DartObjectImpl(typeProvider.doubleType, result); | 505 return new DartObjectImpl(typeProvider.doubleType, result); |
| 507 } else if (result is NumState) { | 506 } else if (result is NumState) { |
| 508 return new DartObjectImpl(typeProvider.numType, result); | 507 return new DartObjectImpl(typeProvider.numType, result); |
| 509 } | 508 } |
| 510 // We should never get here. | 509 // We should never get here. |
| 511 throw new IllegalStateException("minus returned a ${result.runtimeType}"); | 510 throw new StateError("minus returned a ${result.runtimeType}"); |
| 512 } | 511 } |
| 513 | 512 |
| 514 /** | 513 /** |
| 515 * Return the result of invoking the '-' operator on this object. The | 514 * Return the result of invoking the '-' operator on this object. The |
| 516 * [typeProvider] is the type provider used to find known types. | 515 * [typeProvider] is the type provider used to find known types. |
| 517 * | 516 * |
| 518 * Throws an [EvaluationException] if the operator is not appropriate for an | 517 * Throws an [EvaluationException] if the operator is not appropriate for an |
| 519 * object of this kind. | 518 * object of this kind. |
| 520 */ | 519 */ |
| 521 DartObjectImpl negated(TypeProvider typeProvider) { | 520 DartObjectImpl negated(TypeProvider typeProvider) { |
| 522 InstanceState result = _state.negated(); | 521 InstanceState result = _state.negated(); |
| 523 if (result is IntState) { | 522 if (result is IntState) { |
| 524 return new DartObjectImpl(typeProvider.intType, result); | 523 return new DartObjectImpl(typeProvider.intType, result); |
| 525 } else if (result is DoubleState) { | 524 } else if (result is DoubleState) { |
| 526 return new DartObjectImpl(typeProvider.doubleType, result); | 525 return new DartObjectImpl(typeProvider.doubleType, result); |
| 527 } else if (result is NumState) { | 526 } else if (result is NumState) { |
| 528 return new DartObjectImpl(typeProvider.numType, result); | 527 return new DartObjectImpl(typeProvider.numType, result); |
| 529 } | 528 } |
| 530 // We should never get here. | 529 // We should never get here. |
| 531 throw new IllegalStateException("negated returned a ${result.runtimeType}"); | 530 throw new StateError("negated returned a ${result.runtimeType}"); |
| 532 } | 531 } |
| 533 | 532 |
| 534 /** | 533 /** |
| 535 * Return the result of invoking the '!=' operator on this object with the | 534 * Return the result of invoking the '!=' operator on this object with the |
| 536 * [rightOperand]. The [typeProvider] is the type provider used to find known | 535 * [rightOperand]. The [typeProvider] is the type provider used to find known |
| 537 * types. | 536 * types. |
| 538 * | 537 * |
| 539 * Throws an [EvaluationException] if the operator is not appropriate for an | 538 * Throws an [EvaluationException] if the operator is not appropriate for an |
| 540 * object of this kind. | 539 * object of this kind. |
| 541 */ | 540 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 TypeProvider typeProvider, DartObjectImpl rightOperand) { | 581 TypeProvider typeProvider, DartObjectImpl rightOperand) { |
| 583 InstanceState result = _state.remainder(rightOperand._state); | 582 InstanceState result = _state.remainder(rightOperand._state); |
| 584 if (result is IntState) { | 583 if (result is IntState) { |
| 585 return new DartObjectImpl(typeProvider.intType, result); | 584 return new DartObjectImpl(typeProvider.intType, result); |
| 586 } else if (result is DoubleState) { | 585 } else if (result is DoubleState) { |
| 587 return new DartObjectImpl(typeProvider.doubleType, result); | 586 return new DartObjectImpl(typeProvider.doubleType, result); |
| 588 } else if (result is NumState) { | 587 } else if (result is NumState) { |
| 589 return new DartObjectImpl(typeProvider.numType, result); | 588 return new DartObjectImpl(typeProvider.numType, result); |
| 590 } | 589 } |
| 591 // We should never get here. | 590 // We should never get here. |
| 592 throw new IllegalStateException( | 591 throw new StateError("remainder returned a ${result.runtimeType}"); |
| 593 "remainder returned a ${result.runtimeType}"); | |
| 594 } | 592 } |
| 595 | 593 |
| 596 /** | 594 /** |
| 597 * Return the result of invoking the '<<' operator on this object with | 595 * Return the result of invoking the '<<' operator on this object with |
| 598 * the [rightOperand]. The [typeProvider] is the type provider used to find | 596 * the [rightOperand]. The [typeProvider] is the type provider used to find |
| 599 * known types. | 597 * known types. |
| 600 * | 598 * |
| 601 * Throws an [EvaluationException] if the operator is not appropriate for an | 599 * Throws an [EvaluationException] if the operator is not appropriate for an |
| 602 * object of this kind. | 600 * object of this kind. |
| 603 */ | 601 */ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 DartObjectImpl times(TypeProvider typeProvider, DartObjectImpl rightOperand) { | 638 DartObjectImpl times(TypeProvider typeProvider, DartObjectImpl rightOperand) { |
| 641 InstanceState result = _state.times(rightOperand._state); | 639 InstanceState result = _state.times(rightOperand._state); |
| 642 if (result is IntState) { | 640 if (result is IntState) { |
| 643 return new DartObjectImpl(typeProvider.intType, result); | 641 return new DartObjectImpl(typeProvider.intType, result); |
| 644 } else if (result is DoubleState) { | 642 } else if (result is DoubleState) { |
| 645 return new DartObjectImpl(typeProvider.doubleType, result); | 643 return new DartObjectImpl(typeProvider.doubleType, result); |
| 646 } else if (result is NumState) { | 644 } else if (result is NumState) { |
| 647 return new DartObjectImpl(typeProvider.numType, result); | 645 return new DartObjectImpl(typeProvider.numType, result); |
| 648 } | 646 } |
| 649 // We should never get here. | 647 // We should never get here. |
| 650 throw new IllegalStateException("times returned a ${result.runtimeType}"); | 648 throw new StateError("times returned a ${result.runtimeType}"); |
| 651 } | 649 } |
| 652 | 650 |
| 653 @override | 651 @override |
| 654 bool toBoolValue() { | 652 bool toBoolValue() { |
| 655 InstanceState state = _state; | 653 InstanceState state = _state; |
| 656 if (state is BoolState) { | 654 if (state is BoolState) { |
| 657 return state.value; | 655 return state.value; |
| 658 } | 656 } |
| 659 return null; | 657 return null; |
| 660 } | 658 } |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1224 if (rightOperand is IntState) { | 1222 if (rightOperand is IntState) { |
| 1225 return IntState.UNKNOWN_VALUE; | 1223 return IntState.UNKNOWN_VALUE; |
| 1226 } else if (rightOperand is DoubleState) { | 1224 } else if (rightOperand is DoubleState) { |
| 1227 return DoubleState.UNKNOWN_VALUE; | 1225 return DoubleState.UNKNOWN_VALUE; |
| 1228 } | 1226 } |
| 1229 return NumState.UNKNOWN_VALUE; | 1227 return NumState.UNKNOWN_VALUE; |
| 1230 } | 1228 } |
| 1231 } | 1229 } |
| 1232 | 1230 |
| 1233 /** | 1231 /** |
| 1234 * A run-time exception that would be thrown during the evaluation of Dart code. | 1232 * Exception that would be thrown during the evaluation of Dart code. |
| 1235 */ | 1233 */ |
| 1236 class EvaluationException extends JavaException { | 1234 class EvaluationException { |
|
Brian Wilkerson
2016/09/08 22:38:57
Should we do make this a subclass of AnalysisExcep
scheglov
2016/09/08 22:48:12
EvaluationException does not have a message or cau
| |
| 1237 /** | 1235 /** |
| 1238 * The error code associated with the exception. | 1236 * The error code associated with the exception. |
| 1239 */ | 1237 */ |
| 1240 final ErrorCode errorCode; | 1238 final ErrorCode errorCode; |
| 1241 | 1239 |
| 1242 /** | 1240 /** |
| 1243 * Initialize a newly created exception to have the given [errorCode]. | 1241 * Initialize a newly created exception to have the given [errorCode]. |
| 1244 */ | 1242 */ |
| 1245 EvaluationException(this.errorCode); | 1243 EvaluationException(this.errorCode); |
| 1246 } | 1244 } |
| (...skipping 1565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2812 return BoolState.from(_type == rightType); | 2810 return BoolState.from(_type == rightType); |
| 2813 } else if (rightOperand is DynamicState) { | 2811 } else if (rightOperand is DynamicState) { |
| 2814 return BoolState.UNKNOWN_VALUE; | 2812 return BoolState.UNKNOWN_VALUE; |
| 2815 } | 2813 } |
| 2816 return BoolState.FALSE_STATE; | 2814 return BoolState.FALSE_STATE; |
| 2817 } | 2815 } |
| 2818 | 2816 |
| 2819 @override | 2817 @override |
| 2820 String toString() => _type?.toString() ?? "-unknown-"; | 2818 String toString() => _type?.toString() ?? "-unknown-"; |
| 2821 } | 2819 } |
| OLD | NEW |