| 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 analyzer.src.generated.constant; | 5 library analyzer.src.generated.constant; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| 11 import 'package:analyzer/dart/ast/visitor.dart'; | 11 import 'package:analyzer/dart/ast/visitor.dart'; |
| 12 import 'package:analyzer/dart/constant/value.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; | 13 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/dart/element/type.dart'; | 14 import 'package:analyzer/dart/element/type.dart'; |
| 14 import 'package:analyzer/src/dart/ast/utilities.dart'; | 15 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 15 import 'package:analyzer/src/dart/element/element.dart'; | 16 import 'package:analyzer/src/dart/element/element.dart'; |
| 16 import 'package:analyzer/src/dart/element/handle.dart' | 17 import 'package:analyzer/src/dart/element/handle.dart' |
| 17 show ConstructorElementHandle; | 18 show ConstructorElementHandle; |
| 18 import 'package:analyzer/src/dart/element/member.dart'; | 19 import 'package:analyzer/src/dart/element/member.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
| 20 import 'package:analyzer/src/generated/engine.dart' | 21 import 'package:analyzer/src/generated/engine.dart' |
| 21 show AnalysisEngine, RecordingErrorListener; | 22 show AnalysisEngine, RecordingErrorListener; |
| 22 import 'package:analyzer/src/generated/error.dart'; | 23 import 'package:analyzer/src/generated/error.dart'; |
| 23 import 'package:analyzer/src/generated/java_core.dart'; | 24 import 'package:analyzer/src/generated/java_core.dart'; |
| 24 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 25 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
| 25 import 'package:analyzer/src/generated/source.dart' show Source; | 26 import 'package:analyzer/src/generated/source.dart' show Source; |
| 26 import 'package:analyzer/src/generated/type_system.dart' | 27 import 'package:analyzer/src/generated/type_system.dart' |
| 27 show TypeSystem, TypeSystemImpl; | 28 show TypeSystem, TypeSystemImpl; |
| 28 import 'package:analyzer/src/generated/utilities_collection.dart'; | 29 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 29 import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind; | 30 import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind; |
| 30 import 'package:analyzer/src/generated/utilities_general.dart'; | 31 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 31 import 'package:analyzer/src/task/dart.dart'; | 32 import 'package:analyzer/src/task/dart.dart'; |
| 32 | 33 |
| 34 export 'package:analyzer/dart/constant/value.dart'; |
| 35 |
| 33 ConstructorElementImpl _getConstructorImpl(ConstructorElement constructor) { | 36 ConstructorElementImpl _getConstructorImpl(ConstructorElement constructor) { |
| 34 while (constructor is ConstructorMember) { | 37 while (constructor is ConstructorMember) { |
| 35 constructor = (constructor as ConstructorMember).baseElement; | 38 constructor = (constructor as ConstructorMember).baseElement; |
| 36 } | 39 } |
| 37 if (constructor is ConstructorElementHandle) { | 40 if (constructor is ConstructorElementHandle) { |
| 38 constructor = (constructor as ConstructorElementHandle).actualElement; | 41 constructor = (constructor as ConstructorElementHandle).actualElement; |
| 39 } | 42 } |
| 40 return constructor; | 43 return constructor; |
| 41 } | 44 } |
| 42 | 45 |
| (...skipping 1942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 DartObjectImpl _valueOf(Expression expression) { | 1988 DartObjectImpl _valueOf(Expression expression) { |
| 1986 DartObjectImpl expressionValue = expression.accept(this); | 1989 DartObjectImpl expressionValue = expression.accept(this); |
| 1987 if (expressionValue != null) { | 1990 if (expressionValue != null) { |
| 1988 return expressionValue; | 1991 return expressionValue; |
| 1989 } | 1992 } |
| 1990 return _typeProvider.nullObject; | 1993 return _typeProvider.nullObject; |
| 1991 } | 1994 } |
| 1992 } | 1995 } |
| 1993 | 1996 |
| 1994 /** | 1997 /** |
| 1995 * A representation of the value of a compile-time constant expression. | |
| 1996 * | |
| 1997 * Note that, unlike the mirrors system, the object being represented does *not* | |
| 1998 * exist. This interface allows static analysis tools to determine something | |
| 1999 * about the state of the object that would exist if the code that creates the | |
| 2000 * object were executed, but none of the code being analyzed is actually | |
| 2001 * executed. | |
| 2002 */ | |
| 2003 abstract class DartObject { | |
| 2004 /** | |
| 2005 * Return `true` if the value of the object being represented is known. | |
| 2006 * | |
| 2007 * This method will return `false` if | |
| 2008 * * the value being represented is the value of a declared variable (a | |
| 2009 * variable whose value is provided at run-time using a `-D` command-line | |
| 2010 * option), or | |
| 2011 * * the value is a function. | |
| 2012 * | |
| 2013 * The result of this method does not imply anything about the state of | |
| 2014 * object representations returned by the method [getField], those that are | |
| 2015 * elements of the list returned by [toListValue], or the keys or values in | |
| 2016 * the map returned by [toMapValue]. For example, a representation of a list | |
| 2017 * can return `true` even if one or more of the elements of that list would | |
| 2018 * return `false`. | |
| 2019 */ | |
| 2020 bool get hasKnownValue; | |
| 2021 | |
| 2022 /** | |
| 2023 * Return `true` if the object being represented represents the value 'null'. | |
| 2024 */ | |
| 2025 bool get isNull; | |
| 2026 | |
| 2027 /** | |
| 2028 * Return a representation of the type of the object being represented. | |
| 2029 * | |
| 2030 * For values resulting from the invocation of a 'const' constructor, this | |
| 2031 * will be a representation of the run-time type of the object. | |
| 2032 * | |
| 2033 * For values resulting from a literal expression, this will be a | |
| 2034 * representation of the static type of the value -- `int` for integer | |
| 2035 * literals, `List` for list literals, etc. -- even when the static type is an | |
| 2036 * abstract type (such as `List`) and hence will never be the run-time type of | |
| 2037 * the represented object. | |
| 2038 * | |
| 2039 * For values resulting from any other kind of expression, this will be a | |
| 2040 * representation of the result of evaluating the expression. | |
| 2041 * | |
| 2042 * Return `null` if the expression cannot be evaluated, either because it is | |
| 2043 * not a valid constant expression or because one or more of the values used | |
| 2044 * in the expression does not have a known value. | |
| 2045 * | |
| 2046 * This method can return a representation of the type, even if this object | |
| 2047 * would return `false` from [hasKnownValue]. | |
| 2048 */ | |
| 2049 ParameterizedType get type; | |
| 2050 | |
| 2051 /** | |
| 2052 * Return a representation of the value of the field with the given [name]. | |
| 2053 * | |
| 2054 * Return `null` if either the object being represented does not have a field | |
| 2055 * with the given name or if the implementation of the class of the object is | |
| 2056 * invalid, making it impossible to determine that value of the field. | |
| 2057 * | |
| 2058 * Note that, unlike the mirrors API, this method does *not* invoke a getter; | |
| 2059 * it simply returns a representation of the known state of a field. | |
| 2060 */ | |
| 2061 DartObject getField(String name); | |
| 2062 | |
| 2063 /** | |
| 2064 * Return a boolean corresponding to the value of the object being | |
| 2065 * represented, or `null` if | |
| 2066 * * this object is not of type 'bool', | |
| 2067 * * the value of the object being represented is not known, or | |
| 2068 * * the value of the object being represented is `null`. | |
| 2069 */ | |
| 2070 bool toBoolValue(); | |
| 2071 | |
| 2072 /** | |
| 2073 * Return a double corresponding to the value of the object being represented, | |
| 2074 * or `null` | |
| 2075 * if | |
| 2076 * * this object is not of type 'double', | |
| 2077 * * the value of the object being represented is not known, or | |
| 2078 * * the value of the object being represented is `null`. | |
| 2079 */ | |
| 2080 double toDoubleValue(); | |
| 2081 | |
| 2082 /** | |
| 2083 * Return an integer corresponding to the value of the object being | |
| 2084 * represented, or `null` if | |
| 2085 * * this object is not of type 'int', | |
| 2086 * * the value of the object being represented is not known, or | |
| 2087 * * the value of the object being represented is `null`. | |
| 2088 */ | |
| 2089 int toIntValue(); | |
| 2090 | |
| 2091 /** | |
| 2092 * Return a list corresponding to the value of the object being represented, | |
| 2093 * or `null` if | |
| 2094 * * this object is not of type 'List', or | |
| 2095 * * the value of the object being represented is `null`. | |
| 2096 */ | |
| 2097 List<DartObject> toListValue(); | |
| 2098 | |
| 2099 /** | |
| 2100 * Return a map corresponding to the value of the object being represented, or | |
| 2101 * `null` if | |
| 2102 * * this object is not of type 'Map', or | |
| 2103 * * the value of the object being represented is `null`. | |
| 2104 */ | |
| 2105 Map<DartObject, DartObject> toMapValue(); | |
| 2106 | |
| 2107 /** | |
| 2108 * Return a string corresponding to the value of the object being represented, | |
| 2109 * or `null` if | |
| 2110 * * this object is not of type 'String', | |
| 2111 * * the value of the object being represented is not known, or | |
| 2112 * * the value of the object being represented is `null`. | |
| 2113 */ | |
| 2114 String toStringValue(); | |
| 2115 | |
| 2116 /** | |
| 2117 * Return a string corresponding to the value of the object being represented, | |
| 2118 * or `null` if | |
| 2119 * * this object is not of type 'Symbol', or | |
| 2120 * * the value of the object being represented is `null`. | |
| 2121 * (We return the string | |
| 2122 */ | |
| 2123 String toSymbolValue(); | |
| 2124 | |
| 2125 /** | |
| 2126 * Return the representation of the type corresponding to the value of the | |
| 2127 * object being represented, or `null` if | |
| 2128 * * this object is not of type 'Type', or | |
| 2129 * * the value of the object being represented is `null`. | |
| 2130 */ | |
| 2131 DartType toTypeValue(); | |
| 2132 } | |
| 2133 | |
| 2134 /** | |
| 2135 * A utility class that contains methods for manipulating instances of a Dart | 1998 * A utility class that contains methods for manipulating instances of a Dart |
| 2136 * class and for collecting errors during evaluation. | 1999 * class and for collecting errors during evaluation. |
| 2137 */ | 2000 */ |
| 2138 class DartObjectComputer { | 2001 class DartObjectComputer { |
| 2139 /** | 2002 /** |
| 2140 * The error reporter that we are using to collect errors. | 2003 * The error reporter that we are using to collect errors. |
| 2141 */ | 2004 */ |
| 2142 final ErrorReporter _errorReporter; | 2005 final ErrorReporter _errorReporter; |
| 2143 | 2006 |
| 2144 /** | 2007 /** |
| (...skipping 3268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5413 return BoolState.from(_element == rightElement); | 5276 return BoolState.from(_element == rightElement); |
| 5414 } else if (rightOperand is DynamicState) { | 5277 } else if (rightOperand is DynamicState) { |
| 5415 return BoolState.UNKNOWN_VALUE; | 5278 return BoolState.UNKNOWN_VALUE; |
| 5416 } | 5279 } |
| 5417 return BoolState.FALSE_STATE; | 5280 return BoolState.FALSE_STATE; |
| 5418 } | 5281 } |
| 5419 | 5282 |
| 5420 @override | 5283 @override |
| 5421 String toString() => _element == null ? "-unknown-" : _element.name; | 5284 String toString() => _element == null ? "-unknown-" : _element.name; |
| 5422 } | 5285 } |
| OLD | NEW |