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 engine.constant; | 5 library engine.constant; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
10 import 'package:analyzer/src/generated/utilities_general.dart'; | 10 import 'package:analyzer/src/generated/utilities_general.dart'; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 HashMap<String, DartObjectImpl> namedArgumentValues) { | 304 HashMap<String, DartObjectImpl> namedArgumentValues) { |
305 if (arguments.length != 1) { | 305 if (arguments.length != 1) { |
306 return false; | 306 return false; |
307 } | 307 } |
308 if (arguments[0] is NamedExpression) { | 308 if (arguments[0] is NamedExpression) { |
309 return false; | 309 return false; |
310 } | 310 } |
311 if (!identical(argumentValues[0].type, typeProvider.stringType)) { | 311 if (!identical(argumentValues[0].type, typeProvider.stringType)) { |
312 return false; | 312 return false; |
313 } | 313 } |
314 String name = argumentValues[0].stringValue; | 314 String name = argumentValues[0].toStringValue(); |
315 return isValidPublicSymbol(name); | 315 return isValidPublicSymbol(name); |
316 } | 316 } |
317 | 317 |
318 /** | 318 /** |
319 * Compute the constant value associated with the given [constant]. | 319 * Compute the constant value associated with the given [constant]. |
320 */ | 320 */ |
321 void computeConstantValue(ConstantEvaluationTarget constant) { | 321 void computeConstantValue(ConstantEvaluationTarget constant) { |
322 validator.beforeComputeValue(constant); | 322 validator.beforeComputeValue(constant); |
323 if (constant is ParameterElement) { | 323 if (constant is ParameterElement) { |
324 if (constant.initializer != null) { | 324 if (constant.initializer != null) { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 // See if it's because we reached an external const factory constructor | 619 // See if it's because we reached an external const factory constructor |
620 // that we can emulate. | 620 // that we can emulate. |
621 if (constructor.name == "fromEnvironment") { | 621 if (constructor.name == "fromEnvironment") { |
622 if (!checkFromEnvironmentArguments( | 622 if (!checkFromEnvironmentArguments( |
623 arguments, argumentValues, namedArgumentValues, definingClass)) { | 623 arguments, argumentValues, namedArgumentValues, definingClass)) { |
624 errorReporter.reportErrorForNode( | 624 errorReporter.reportErrorForNode( |
625 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); | 625 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); |
626 return null; | 626 return null; |
627 } | 627 } |
628 String variableName = | 628 String variableName = |
629 argumentCount < 1 ? null : argumentValues[0].stringValue; | 629 argumentCount < 1 ? null : argumentValues[0].toStringValue(); |
630 if (identical(definingClass, typeProvider.boolType)) { | 630 if (identical(definingClass, typeProvider.boolType)) { |
631 DartObject valueFromEnvironment; | 631 DartObject valueFromEnvironment; |
632 valueFromEnvironment = | 632 valueFromEnvironment = |
633 _declaredVariables.getBool(typeProvider, variableName); | 633 _declaredVariables.getBool(typeProvider, variableName); |
634 return computeValueFromEnvironment( | 634 return computeValueFromEnvironment( |
635 valueFromEnvironment, | 635 valueFromEnvironment, |
636 new DartObjectImpl(typeProvider.boolType, BoolState.FALSE_STATE), | 636 new DartObjectImpl(typeProvider.boolType, BoolState.FALSE_STATE), |
637 namedArgumentValues); | 637 namedArgumentValues); |
638 } else if (identical(definingClass, typeProvider.intType)) { | 638 } else if (identical(definingClass, typeProvider.intType)) { |
639 DartObject valueFromEnvironment; | 639 DartObject valueFromEnvironment; |
(...skipping 14 matching lines...) Expand all Loading... |
654 } | 654 } |
655 } else if (constructor.name == "" && | 655 } else if (constructor.name == "" && |
656 identical(definingClass, typeProvider.symbolType) && | 656 identical(definingClass, typeProvider.symbolType) && |
657 argumentCount == 1) { | 657 argumentCount == 1) { |
658 if (!checkSymbolArguments( | 658 if (!checkSymbolArguments( |
659 arguments, argumentValues, namedArgumentValues)) { | 659 arguments, argumentValues, namedArgumentValues)) { |
660 errorReporter.reportErrorForNode( | 660 errorReporter.reportErrorForNode( |
661 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); | 661 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node); |
662 return null; | 662 return null; |
663 } | 663 } |
664 String argumentValue = argumentValues[0].stringValue; | 664 String argumentValue = argumentValues[0].toStringValue(); |
665 return new DartObjectImpl( | 665 return new DartObjectImpl( |
666 definingClass, new SymbolState(argumentValue)); | 666 definingClass, new SymbolState(argumentValue)); |
667 } | 667 } |
668 // Either it's an external const factory constructor that we can't | 668 // Either it's an external const factory constructor that we can't |
669 // emulate, or an error occurred (a cycle, or a const constructor trying | 669 // emulate, or an error occurred (a cycle, or a const constructor trying |
670 // to delegate to a non-const constructor). | 670 // to delegate to a non-const constructor). |
671 // In the former case, the best we can do is consider it an unknown value. | 671 // In the former case, the best we can do is consider it an unknown value. |
672 // In the latter case, the error has already been reported, so considering | 672 // In the latter case, the error has already been reported, so considering |
673 // it an unknown value will suppress further errors. | 673 // it an unknown value will suppress further errors. |
674 return new DartObjectImpl.validWithUnknownValue(definingClass); | 674 return new DartObjectImpl.validWithUnknownValue(definingClass); |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 } else if (thenResult == null) { | 1591 } else if (thenResult == null) { |
1592 return thenResult; | 1592 return thenResult; |
1593 } else if (elseResult == null) { | 1593 } else if (elseResult == null) { |
1594 return elseResult; | 1594 return elseResult; |
1595 } | 1595 } |
1596 conditionResult = | 1596 conditionResult = |
1597 _dartObjectComputer.applyBooleanConversion(condition, conditionResult); | 1597 _dartObjectComputer.applyBooleanConversion(condition, conditionResult); |
1598 if (conditionResult == null) { | 1598 if (conditionResult == null) { |
1599 return conditionResult; | 1599 return conditionResult; |
1600 } | 1600 } |
1601 if (conditionResult.isTrue) { | 1601 if (conditionResult.toBoolValue() == true) { |
1602 return thenResult; | 1602 return thenResult; |
1603 } else if (conditionResult.isFalse) { | 1603 } else if (conditionResult.toBoolValue() == false) { |
1604 return elseResult; | 1604 return elseResult; |
1605 } | 1605 } |
1606 ParameterizedType thenType = thenResult.type; | 1606 ParameterizedType thenType = thenResult.type; |
1607 ParameterizedType elseType = elseResult.type; | 1607 ParameterizedType elseType = elseResult.type; |
1608 return new DartObjectImpl.validWithUnknownValue( | 1608 return new DartObjectImpl.validWithUnknownValue( |
1609 _typeSystem.getLeastUpperBound(_typeProvider, thenType, elseType) | 1609 _typeSystem.getLeastUpperBound(_typeProvider, thenType, elseType) |
1610 as InterfaceType); | 1610 as InterfaceType); |
1611 } | 1611 } |
1612 | 1612 |
1613 @override | 1613 @override |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1929 DartObjectImpl _valueOf(Expression expression) { | 1929 DartObjectImpl _valueOf(Expression expression) { |
1930 DartObjectImpl expressionValue = expression.accept(this); | 1930 DartObjectImpl expressionValue = expression.accept(this); |
1931 if (expressionValue != null) { | 1931 if (expressionValue != null) { |
1932 return expressionValue; | 1932 return expressionValue; |
1933 } | 1933 } |
1934 return _typeProvider.nullObject; | 1934 return _typeProvider.nullObject; |
1935 } | 1935 } |
1936 } | 1936 } |
1937 | 1937 |
1938 /** | 1938 /** |
1939 * The state of a Dart object. | 1939 * A representation of the value of a compile-time constant expression. |
| 1940 * |
| 1941 * Note that, unlike the mirrors system, the object being represented does *not* |
| 1942 * exist. This interface allows static analysis tools to determine something |
| 1943 * about the state of the object that would exist if the code that creates the |
| 1944 * object were executed, but none of the code being analyzed is actually |
| 1945 * executed. |
1940 */ | 1946 */ |
1941 abstract class DartObject { | 1947 abstract class DartObject { |
1942 /** | 1948 /** |
1943 * Return the boolean value of this object, or `null` if either the value of | 1949 * Return the boolean value of this object, or `null` if either the value of |
1944 * this object is not known or this object is not of type 'bool'. | 1950 * this object is not known or this object is not of type 'bool'. |
1945 */ | 1951 * |
| 1952 * Deprecated. Use [toBoolValue]. |
| 1953 */ |
| 1954 @deprecated |
1946 bool get boolValue; | 1955 bool get boolValue; |
1947 | 1956 |
1948 /** | 1957 /** |
1949 * Return the floating point value of this object, or `null` if either the | 1958 * Return the floating point value of this object, or `null` if either the |
1950 * value of this object is not known or this object is not of type 'double'. | 1959 * value of this object is not known or this object is not of type 'double'. |
1951 */ | 1960 * |
| 1961 * Deprecated. Use [toDoubleValue]. |
| 1962 */ |
| 1963 @deprecated |
1952 double get doubleValue; | 1964 double get doubleValue; |
1953 | 1965 |
1954 /** | 1966 /** |
1955 * Return `true` if this object's value can be represented exactly. | 1967 * Return `true` if this object's value can be represented exactly. |
1956 */ | 1968 * |
| 1969 * Deprecated. The semantics of this method were not clear. One semantic is |
| 1970 * covered by [hasKnownValue]. |
| 1971 */ |
| 1972 @deprecated |
1957 bool get hasExactValue; | 1973 bool get hasExactValue; |
1958 | 1974 |
1959 /** | 1975 /** |
| 1976 * Return `true` if the value of the object being represented is known. |
| 1977 * |
| 1978 * This method will return `false` if |
| 1979 * * the value being represented is the value of a declared variable (a |
| 1980 * variable whose value is provided at run-time using a `-D` command-line |
| 1981 * option), or |
| 1982 * * the value is a function. |
| 1983 * |
| 1984 * The result of this method does not imply anything about the state of |
| 1985 * object representations returned by the method [getField], those that are |
| 1986 * elements of the list returned by [toListValue], or the keys or values in |
| 1987 * the map returned by [toMapValue]. For example, a representation of a list |
| 1988 * can return `true` even if one or more of the elements of that list would |
| 1989 * return `false`. |
| 1990 */ |
| 1991 bool get hasKnownValue; |
| 1992 |
| 1993 /** |
1960 * Return the integer value of this object, or `null` if either the value of | 1994 * Return the integer value of this object, or `null` if either the value of |
1961 * this object is not known or this object is not of type 'int'. | 1995 * this object is not known or this object is not of type 'int'. |
1962 */ | 1996 * |
| 1997 * Deprecated. Use [toIntValue]. |
| 1998 */ |
| 1999 @deprecated |
1963 int get intValue; | 2000 int get intValue; |
1964 | 2001 |
1965 /** | 2002 /** |
1966 * Return `true` if this object represents the value 'false'. | 2003 * Return `true` if this object represents the value 'false'. |
1967 */ | 2004 * |
| 2005 * Deprecated. Use `object.toBoolValue() == false`. |
| 2006 */ |
| 2007 @deprecated |
1968 bool get isFalse; | 2008 bool get isFalse; |
1969 | 2009 |
1970 /** | 2010 /** |
1971 * Return `true` if this object represents the value 'null'. | 2011 * Return `true` if the object being represented represents the value 'null'. |
1972 */ | 2012 */ |
1973 bool get isNull; | 2013 bool get isNull; |
1974 | 2014 |
1975 /** | 2015 /** |
1976 * Return `true` if this object represents the value 'true'. | 2016 * Return `true` if this object represents the value 'true'. |
1977 */ | 2017 * |
| 2018 * Deprecated. Use `object.toBoolValue() == true`. |
| 2019 */ |
| 2020 @deprecated |
1978 bool get isTrue; | 2021 bool get isTrue; |
1979 | 2022 |
1980 /** | 2023 /** |
1981 * Return the string value of this object, or `null` if either the value of | 2024 * Return the string value of this object, or `null` if either the value of |
1982 * this object is not known or this object is not of type 'String'. | 2025 * this object is not known or this object is not of type 'String'. |
1983 */ | 2026 * |
| 2027 * Deprecated. Use [toStringValue]. |
| 2028 */ |
| 2029 @deprecated |
1984 String get stringValue; | 2030 String get stringValue; |
1985 | 2031 |
1986 /** | 2032 /** |
1987 * Return the run-time type of this object. | 2033 * Return a representation of the type of the object being represented. |
| 2034 * |
| 2035 * For values resulting from the invocation of a 'const' constructor, this |
| 2036 * will be a representation of the run-time type of the object. |
| 2037 * |
| 2038 * For values resulting from a literal expression, this will be a |
| 2039 * representation of the static type of the value -- `int` for integer |
| 2040 * literals, `List` for list literals, etc. -- even when the static type is an |
| 2041 * abstract type (such as `List`) and hence will never be the run-time type of |
| 2042 * the represented object. |
| 2043 * |
| 2044 * For values resulting from any other kind of expression, this will be a |
| 2045 * representation of the result of evaluating the expression. |
| 2046 * |
| 2047 * Return `null` if the expression cannot be evaluated, either because it is |
| 2048 * not a valid constant expression or because one or more of the values used |
| 2049 * in the expression does not have a known value. |
| 2050 * |
| 2051 * This method can return a representation of the type, even if this object |
| 2052 * would return `false` from [hasKnownValue]. |
1988 */ | 2053 */ |
1989 ParameterizedType get type; | 2054 ParameterizedType get type; |
1990 | 2055 |
1991 /** | 2056 /** |
1992 * Return this object's value if it can be represented exactly, or `null` if | 2057 * Return this object's value if it can be represented exactly, or `null` if |
1993 * either the value cannot be represented exactly or if the value is `null`. | 2058 * either the value cannot be represented exactly or if the value is `null`. |
1994 * Clients should use [hasExactValue] to distinguish between these two cases. | 2059 * Clients should use `hasExactValue` to distinguish between these two cases. |
1995 */ | 2060 * |
| 2061 * Deprecated. Use one of the `isXValue()` methods. |
| 2062 */ |
| 2063 @deprecated |
1996 Object get value; | 2064 Object get value; |
| 2065 |
| 2066 /** |
| 2067 * Return a representation of the value of the field with the given [name]. |
| 2068 * |
| 2069 * Return `null` if either the object being represented does not have a field |
| 2070 * with the given name or if the implementation of the class of the object is |
| 2071 * invalid, making it impossible to determine that value of the field. |
| 2072 * |
| 2073 * Note that, unlike the mirrors API, this method does *not* invoke a getter; |
| 2074 * it simply returns a representation of the known state of a field. |
| 2075 */ |
| 2076 DartObject getField(String name); |
| 2077 |
| 2078 /** |
| 2079 * Return a boolean corresponding to the value of the object being |
| 2080 * represented, or `null` if |
| 2081 * * this object is not of type 'bool', |
| 2082 * * the value of the object being represented is not known, or |
| 2083 * * the value of the object being represented is `null`. |
| 2084 */ |
| 2085 bool toBoolValue(); |
| 2086 |
| 2087 /** |
| 2088 * Return a double corresponding to the value of the object being represented, |
| 2089 * or `null` |
| 2090 * if |
| 2091 * * this object is not of type 'double', |
| 2092 * * the value of the object being represented is not known, or |
| 2093 * * the value of the object being represented is `null`. |
| 2094 */ |
| 2095 double toDoubleValue(); |
| 2096 |
| 2097 /** |
| 2098 * Return an integer corresponding to the value of the object being |
| 2099 * represented, or `null` if |
| 2100 * * this object is not of type 'int', |
| 2101 * * the value of the object being represented is not known, or |
| 2102 * * the value of the object being represented is `null`. |
| 2103 */ |
| 2104 int toIntValue(); |
| 2105 |
| 2106 /** |
| 2107 * Return a list corresponding to the value of the object being represented, |
| 2108 * or `null` if |
| 2109 * * this object is not of type 'List', or |
| 2110 * * the value of the object being represented is `null`. |
| 2111 */ |
| 2112 List<DartObject> toListValue(); |
| 2113 |
| 2114 /** |
| 2115 * Return a map corresponding to the value of the object being represented, or |
| 2116 * `null` if |
| 2117 * * this object is not of type 'Map', or |
| 2118 * * the value of the object being represented is `null`. |
| 2119 */ |
| 2120 Map<DartObject, DartObject> toMapValue(); |
| 2121 |
| 2122 /** |
| 2123 * Return a string corresponding to the value of the object being represented, |
| 2124 * or `null` if |
| 2125 * * this object is not of type 'String', |
| 2126 * * the value of the object being represented is not known, or |
| 2127 * * the value of the object being represented is `null`. |
| 2128 */ |
| 2129 String toStringValue(); |
| 2130 |
| 2131 /** |
| 2132 * Return a string corresponding to the value of the object being represented, |
| 2133 * or `null` if |
| 2134 * * this object is not of type 'Symbol', or |
| 2135 * * the value of the object being represented is `null`. |
| 2136 * (We return the string |
| 2137 */ |
| 2138 String toSymbolValue(); |
| 2139 |
| 2140 /** |
| 2141 * Return the representation of the type corresponding to the value of the |
| 2142 * object being represented, or `null` if |
| 2143 * * this object is not of type 'Type', or |
| 2144 * * the value of the object being represented is `null`. |
| 2145 */ |
| 2146 ParameterizedType toTypeValue(); |
1997 } | 2147 } |
1998 | 2148 |
1999 /** | 2149 /** |
2000 * A utility class that contains methods for manipulating instances of a Dart | 2150 * A utility class that contains methods for manipulating instances of a Dart |
2001 * class and for collecting errors during evaluation. | 2151 * class and for collecting errors during evaluation. |
2002 */ | 2152 */ |
2003 class DartObjectComputer { | 2153 class DartObjectComputer { |
2004 /** | 2154 /** |
2005 * The error reporter that we are using to collect errors. | 2155 * The error reporter that we are using to collect errors. |
2006 */ | 2156 */ |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2383 return new DartObjectImpl(type, DoubleState.UNKNOWN_VALUE); | 2533 return new DartObjectImpl(type, DoubleState.UNKNOWN_VALUE); |
2384 } else if (typeName == "int") { | 2534 } else if (typeName == "int") { |
2385 return new DartObjectImpl(type, IntState.UNKNOWN_VALUE); | 2535 return new DartObjectImpl(type, IntState.UNKNOWN_VALUE); |
2386 } else if (typeName == "String") { | 2536 } else if (typeName == "String") { |
2387 return new DartObjectImpl(type, StringState.UNKNOWN_VALUE); | 2537 return new DartObjectImpl(type, StringState.UNKNOWN_VALUE); |
2388 } | 2538 } |
2389 } | 2539 } |
2390 return new DartObjectImpl(type, GenericState.UNKNOWN_VALUE); | 2540 return new DartObjectImpl(type, GenericState.UNKNOWN_VALUE); |
2391 } | 2541 } |
2392 | 2542 |
| 2543 @deprecated |
2393 @override | 2544 @override |
2394 bool get boolValue { | 2545 bool get boolValue => toBoolValue(); |
2395 if (_state is BoolState) { | |
2396 return (_state as BoolState).value; | |
2397 } | |
2398 return null; | |
2399 } | |
2400 | 2546 |
| 2547 @deprecated |
2401 @override | 2548 @override |
2402 double get doubleValue { | 2549 double get doubleValue => toDoubleValue(); |
2403 if (_state is DoubleState) { | |
2404 return (_state as DoubleState).value; | |
2405 } | |
2406 return null; | |
2407 } | |
2408 | 2550 |
2409 HashMap<String, DartObjectImpl> get fields => _state.fields; | 2551 HashMap<String, DartObjectImpl> get fields => _state.fields; |
2410 | 2552 |
| 2553 @deprecated |
2411 @override | 2554 @override |
2412 bool get hasExactValue => _state.hasExactValue; | 2555 bool get hasExactValue => _state.hasExactValue; |
2413 | 2556 |
2414 @override | 2557 @override |
2415 int get hashCode => JenkinsSmiHash.hash2(type.hashCode, _state.hashCode); | 2558 int get hashCode => JenkinsSmiHash.hash2(type.hashCode, _state.hashCode); |
2416 | 2559 |
2417 @override | 2560 @override |
2418 int get intValue { | 2561 bool get hasKnownValue => !_state.isUnknown; |
2419 if (_state is IntState) { | 2562 |
2420 return (_state as IntState).value; | 2563 @deprecated |
2421 } | 2564 @override |
2422 return null; | 2565 int get intValue => toIntValue(); |
2423 } | |
2424 | 2566 |
2425 /** | 2567 /** |
2426 * Return `true` if this object represents an object whose type is 'bool'. | 2568 * Return `true` if this object represents an object whose type is 'bool'. |
2427 */ | 2569 */ |
2428 bool get isBool => _state.isBool; | 2570 bool get isBool => _state.isBool; |
2429 | 2571 |
2430 /** | 2572 /** |
2431 * Return `true` if this object represents an object whose type is either | 2573 * Return `true` if this object represents an object whose type is either |
2432 * 'bool', 'num', 'String', or 'Null'. | 2574 * 'bool', 'num', 'String', or 'Null'. |
2433 */ | 2575 */ |
2434 bool get isBoolNumStringOrNull => _state.isBoolNumStringOrNull; | 2576 bool get isBoolNumStringOrNull => _state.isBoolNumStringOrNull; |
2435 | 2577 |
| 2578 @deprecated |
2436 @override | 2579 @override |
2437 bool get isFalse => | 2580 bool get isFalse => toBoolValue() == false; |
2438 _state is BoolState && identical((_state as BoolState).value, false); | |
2439 | 2581 |
2440 @override | 2582 @override |
2441 bool get isNull => _state is NullState; | 2583 bool get isNull => _state is NullState; |
2442 | 2584 |
| 2585 @deprecated |
2443 @override | 2586 @override |
2444 bool get isTrue => | 2587 bool get isTrue => |
2445 _state is BoolState && identical((_state as BoolState).value, true); | 2588 _state is BoolState && identical((_state as BoolState).value, true); |
2446 | 2589 |
2447 /** | 2590 /** |
2448 * Return `true` if this object represents an unknown value. | 2591 * Return `true` if this object represents an unknown value. |
2449 */ | 2592 */ |
2450 bool get isUnknown => _state.isUnknown; | 2593 bool get isUnknown => _state.isUnknown; |
2451 | 2594 |
2452 /** | 2595 /** |
2453 * Return `true` if this object represents an instance of a user-defined | 2596 * Return `true` if this object represents an instance of a user-defined |
2454 * class. | 2597 * class. |
2455 */ | 2598 */ |
2456 bool get isUserDefinedObject => _state is GenericState; | 2599 bool get isUserDefinedObject => _state is GenericState; |
2457 | 2600 |
| 2601 @deprecated |
2458 @override | 2602 @override |
2459 String get stringValue { | 2603 String get stringValue => toStringValue(); |
2460 if (_state is StringState) { | |
2461 return (_state as StringState).value; | |
2462 } | |
2463 return null; | |
2464 } | |
2465 | 2604 |
| 2605 @deprecated |
2466 @override | 2606 @override |
2467 Object get value => _state.value; | 2607 Object get value => _state.value; |
2468 | 2608 |
2469 @override | 2609 @override |
2470 bool operator ==(Object object) { | 2610 bool operator ==(Object object) { |
2471 if (object is! DartObjectImpl) { | 2611 if (object is! DartObjectImpl) { |
2472 return false; | 2612 return false; |
2473 } | 2613 } |
2474 DartObjectImpl dartObject = object as DartObjectImpl; | 2614 DartObjectImpl dartObject = object as DartObjectImpl; |
2475 return type == dartObject.type && _state == dartObject._state; | 2615 return type == dartObject.type && _state == dartObject._state; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2617 typeName == "Null" || | 2757 typeName == "Null" || |
2618 type.isDynamic)) { | 2758 type.isDynamic)) { |
2619 throw new EvaluationException( | 2759 throw new EvaluationException( |
2620 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING); | 2760 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING); |
2621 } | 2761 } |
2622 } | 2762 } |
2623 return new DartObjectImpl( | 2763 return new DartObjectImpl( |
2624 typeProvider.boolType, _state.equalEqual(rightOperand._state)); | 2764 typeProvider.boolType, _state.equalEqual(rightOperand._state)); |
2625 } | 2765 } |
2626 | 2766 |
| 2767 @override |
| 2768 DartObject getField(String name) { |
| 2769 if (_state is GenericState) { |
| 2770 return (_state as GenericState).fields[name]; |
| 2771 } |
| 2772 return null; |
| 2773 } |
| 2774 |
2627 /** | 2775 /** |
2628 * Return the result of invoking the '>' operator on this object with the | 2776 * Return the result of invoking the '>' operator on this object with the |
2629 * [rightOperand]. The [typeProvider] is the type provider used to find known | 2777 * [rightOperand]. The [typeProvider] is the type provider used to find known |
2630 * types. | 2778 * types. |
2631 * | 2779 * |
2632 * Throws an [EvaluationException] if the operator is not appropriate for an | 2780 * Throws an [EvaluationException] if the operator is not appropriate for an |
2633 * object of this kind. | 2781 * object of this kind. |
2634 */ | 2782 */ |
2635 DartObjectImpl greaterThan( | 2783 DartObjectImpl greaterThan( |
2636 TypeProvider typeProvider, DartObjectImpl rightOperand) => | 2784 TypeProvider typeProvider, DartObjectImpl rightOperand) => |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2890 } else if (result is DoubleState) { | 3038 } else if (result is DoubleState) { |
2891 return new DartObjectImpl(typeProvider.doubleType, result); | 3039 return new DartObjectImpl(typeProvider.doubleType, result); |
2892 } else if (result is NumState) { | 3040 } else if (result is NumState) { |
2893 return new DartObjectImpl(typeProvider.numType, result); | 3041 return new DartObjectImpl(typeProvider.numType, result); |
2894 } | 3042 } |
2895 // We should never get here. | 3043 // We should never get here. |
2896 throw new IllegalStateException("times returned a ${result.runtimeType}"); | 3044 throw new IllegalStateException("times returned a ${result.runtimeType}"); |
2897 } | 3045 } |
2898 | 3046 |
2899 @override | 3047 @override |
| 3048 bool toBoolValue() { |
| 3049 if (_state is BoolState) { |
| 3050 return (_state as BoolState).value; |
| 3051 } |
| 3052 return null; |
| 3053 } |
| 3054 |
| 3055 @override |
| 3056 double toDoubleValue() { |
| 3057 if (_state is DoubleState) { |
| 3058 return (_state as DoubleState).value; |
| 3059 } |
| 3060 return null; |
| 3061 } |
| 3062 |
| 3063 @override |
| 3064 int toIntValue() { |
| 3065 if (_state is IntState) { |
| 3066 return (_state as IntState).value; |
| 3067 } |
| 3068 return null; |
| 3069 } |
| 3070 |
| 3071 @override |
| 3072 List<DartObject> toListValue() { |
| 3073 if (_state is ListState) { |
| 3074 return (_state as ListState)._elements; |
| 3075 } |
| 3076 return null; |
| 3077 } |
| 3078 |
| 3079 @override |
| 3080 Map<DartObject, DartObject> toMapValue() { |
| 3081 if (_state is MapState) { |
| 3082 return (_state as MapState)._entries; |
| 3083 } |
| 3084 return null; |
| 3085 } |
| 3086 |
| 3087 @override |
2900 String toString() => "${type.displayName} ($_state)"; | 3088 String toString() => "${type.displayName} ($_state)"; |
| 3089 |
| 3090 @override |
| 3091 String toStringValue() { |
| 3092 if (_state is StringState) { |
| 3093 return (_state as StringState).value; |
| 3094 } |
| 3095 return null; |
| 3096 } |
| 3097 |
| 3098 @override |
| 3099 String toSymbolValue() { |
| 3100 if (_state is SymbolState) { |
| 3101 return (_state as SymbolState).value; |
| 3102 } |
| 3103 return null; |
| 3104 } |
| 3105 |
| 3106 @override |
| 3107 ParameterizedType toTypeValue() { |
| 3108 if (_state is TypeState) { |
| 3109 Element element = (_state as TypeState).value; |
| 3110 if (element is ClassElement) { |
| 3111 return element.type; |
| 3112 } |
| 3113 if (element is FunctionElement) { |
| 3114 return element.type; |
| 3115 } |
| 3116 } |
| 3117 return null; |
| 3118 } |
2901 } | 3119 } |
2902 | 3120 |
2903 /** | 3121 /** |
2904 * An object used to provide access to the values of variables that have been | 3122 * An object used to provide access to the values of variables that have been |
2905 * defined on the command line using the `-D` option. | 3123 * defined on the command line using the `-D` option. |
2906 */ | 3124 */ |
2907 class DeclaredVariables { | 3125 class DeclaredVariables { |
2908 /** | 3126 /** |
2909 * A table mapping the names of declared variables to their values. | 3127 * A table mapping the names of declared variables to their values. |
2910 */ | 3128 */ |
(...skipping 2412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5323 return BoolState.from(_element == rightElement); | 5541 return BoolState.from(_element == rightElement); |
5324 } else if (rightOperand is DynamicState) { | 5542 } else if (rightOperand is DynamicState) { |
5325 return BoolState.UNKNOWN_VALUE; | 5543 return BoolState.UNKNOWN_VALUE; |
5326 } | 5544 } |
5327 return BoolState.FALSE_STATE; | 5545 return BoolState.FALSE_STATE; |
5328 } | 5546 } |
5329 | 5547 |
5330 @override | 5548 @override |
5331 String toString() => _element == null ? "-unknown-" : _element.name; | 5549 String toString() => _element == null ? "-unknown-" : _element.name; |
5332 } | 5550 } |
OLD | NEW |