| 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'; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 throw new EvaluationException( | 365 throw new EvaluationException( |
| 366 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING); | 366 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING); |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 return new DartObjectImpl( | 369 return new DartObjectImpl( |
| 370 typeProvider.boolType, _state.equalEqual(rightOperand._state)); | 370 typeProvider.boolType, _state.equalEqual(rightOperand._state)); |
| 371 } | 371 } |
| 372 | 372 |
| 373 @override | 373 @override |
| 374 DartObject getField(String name) { | 374 DartObject getField(String name) { |
| 375 if (_state is GenericState) { | 375 InstanceState state = _state; |
| 376 return (_state as GenericState).fields[name]; | 376 if (state is GenericState) { |
| 377 return state.fields[name]; |
| 377 } | 378 } |
| 378 return null; | 379 return null; |
| 379 } | 380 } |
| 380 | 381 |
| 381 /** | 382 /** |
| 382 * Return the result of invoking the '>' operator on this object with the | 383 * Return the result of invoking the '>' operator on this object with the |
| 383 * [rightOperand]. The [typeProvider] is the type provider used to find known | 384 * [rightOperand]. The [typeProvider] is the type provider used to find known |
| 384 * types. | 385 * types. |
| 385 * | 386 * |
| 386 * Throws an [EvaluationException] if the operator is not appropriate for an | 387 * Throws an [EvaluationException] if the operator is not appropriate for an |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 return new DartObjectImpl(typeProvider.doubleType, result); | 646 return new DartObjectImpl(typeProvider.doubleType, result); |
| 646 } else if (result is NumState) { | 647 } else if (result is NumState) { |
| 647 return new DartObjectImpl(typeProvider.numType, result); | 648 return new DartObjectImpl(typeProvider.numType, result); |
| 648 } | 649 } |
| 649 // We should never get here. | 650 // We should never get here. |
| 650 throw new IllegalStateException("times returned a ${result.runtimeType}"); | 651 throw new IllegalStateException("times returned a ${result.runtimeType}"); |
| 651 } | 652 } |
| 652 | 653 |
| 653 @override | 654 @override |
| 654 bool toBoolValue() { | 655 bool toBoolValue() { |
| 655 if (_state is BoolState) { | 656 InstanceState state = _state; |
| 656 return (_state as BoolState).value; | 657 if (state is BoolState) { |
| 658 return state.value; |
| 657 } | 659 } |
| 658 return null; | 660 return null; |
| 659 } | 661 } |
| 660 | 662 |
| 661 @override | 663 @override |
| 662 double toDoubleValue() { | 664 double toDoubleValue() { |
| 663 if (_state is DoubleState) { | 665 InstanceState state = _state; |
| 664 return (_state as DoubleState).value; | 666 if (state is DoubleState) { |
| 667 return state.value; |
| 665 } | 668 } |
| 666 return null; | 669 return null; |
| 667 } | 670 } |
| 668 | 671 |
| 669 @override | 672 @override |
| 670 int toIntValue() { | 673 int toIntValue() { |
| 671 if (_state is IntState) { | 674 InstanceState state = _state; |
| 672 return (_state as IntState).value; | 675 if (state is IntState) { |
| 676 return state.value; |
| 673 } | 677 } |
| 674 return null; | 678 return null; |
| 675 } | 679 } |
| 676 | 680 |
| 677 @override | 681 @override |
| 678 List<DartObject> toListValue() { | 682 List<DartObject> toListValue() { |
| 679 if (_state is ListState) { | 683 InstanceState state = _state; |
| 680 return (_state as ListState)._elements; | 684 if (state is ListState) { |
| 685 return state._elements; |
| 681 } | 686 } |
| 682 return null; | 687 return null; |
| 683 } | 688 } |
| 684 | 689 |
| 685 @override | 690 @override |
| 686 Map<DartObject, DartObject> toMapValue() { | 691 Map<DartObject, DartObject> toMapValue() { |
| 687 if (_state is MapState) { | 692 InstanceState state = _state; |
| 688 return (_state as MapState)._entries; | 693 if (state is MapState) { |
| 694 return state._entries; |
| 689 } | 695 } |
| 690 return null; | 696 return null; |
| 691 } | 697 } |
| 692 | 698 |
| 693 @override | 699 @override |
| 694 String toString() => "${type.displayName} ($_state)"; | 700 String toString() => "${type.displayName} ($_state)"; |
| 695 | 701 |
| 696 @override | 702 @override |
| 697 String toStringValue() { | 703 String toStringValue() { |
| 698 if (_state is StringState) { | 704 InstanceState state = _state; |
| 699 return (_state as StringState).value; | 705 if (state is StringState) { |
| 706 return state.value; |
| 700 } | 707 } |
| 701 return null; | 708 return null; |
| 702 } | 709 } |
| 703 | 710 |
| 704 @override | 711 @override |
| 705 String toSymbolValue() { | 712 String toSymbolValue() { |
| 706 if (_state is SymbolState) { | 713 InstanceState state = _state; |
| 707 return (_state as SymbolState).value; | 714 if (state is SymbolState) { |
| 715 return state.value; |
| 708 } | 716 } |
| 709 return null; | 717 return null; |
| 710 } | 718 } |
| 711 | 719 |
| 712 @override | 720 @override |
| 713 DartType toTypeValue() { | 721 DartType toTypeValue() { |
| 714 if (_state is TypeState) { | 722 InstanceState state = _state; |
| 715 Element element = (_state as TypeState)._element; | 723 if (state is TypeState) { |
| 724 Element element = state._element; |
| 716 if (element is TypeDefiningElement) { | 725 if (element is TypeDefiningElement) { |
| 717 return element.type; | 726 return element.type; |
| 718 } | 727 } |
| 719 } | 728 } |
| 720 return null; | 729 return null; |
| 721 } | 730 } |
| 722 } | 731 } |
| 723 | 732 |
| 724 /** | 733 /** |
| 725 * The state of an object representing a double. | 734 * The state of an object representing a double. |
| (...skipping 2083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2809 return BoolState.from(_element == rightElement); | 2818 return BoolState.from(_element == rightElement); |
| 2810 } else if (rightOperand is DynamicState) { | 2819 } else if (rightOperand is DynamicState) { |
| 2811 return BoolState.UNKNOWN_VALUE; | 2820 return BoolState.UNKNOWN_VALUE; |
| 2812 } | 2821 } |
| 2813 return BoolState.FALSE_STATE; | 2822 return BoolState.FALSE_STATE; |
| 2814 } | 2823 } |
| 2815 | 2824 |
| 2816 @override | 2825 @override |
| 2817 String toString() => _element == null ? "-unknown-" : _element.name; | 2826 String toString() => _element == null ? "-unknown-" : _element.name; |
| 2818 } | 2827 } |
| OLD | NEW |