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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 String toString() => value == null ? "-unknown-" : (value ? "true" : "false"); | 129 String toString() => value == null ? "-unknown-" : (value ? "true" : "false"); |
130 | 130 |
131 /** | 131 /** |
132 * Return the boolean state representing the given boolean [value]. | 132 * Return the boolean state representing the given boolean [value]. |
133 */ | 133 */ |
134 static BoolState from(bool value) => | 134 static BoolState from(bool value) => |
135 value ? BoolState.TRUE_STATE : BoolState.FALSE_STATE; | 135 value ? BoolState.TRUE_STATE : BoolState.FALSE_STATE; |
136 } | 136 } |
137 | 137 |
138 /** | 138 /** |
| 139 * Information about a const constructor invocation. |
| 140 */ |
| 141 class ConstructorInvocation { |
| 142 /** |
| 143 * The constructor that was called. |
| 144 */ |
| 145 final ConstructorElement constructor; |
| 146 |
| 147 /** |
| 148 * The positional arguments passed to the constructor. |
| 149 */ |
| 150 final List<DartObjectImpl> positionalArguments; |
| 151 |
| 152 /** |
| 153 * The named arguments passed to the constructor. |
| 154 */ |
| 155 final Map<String, DartObjectImpl> namedArguments; |
| 156 |
| 157 ConstructorInvocation( |
| 158 this.constructor, this.positionalArguments, this.namedArguments); |
| 159 } |
| 160 |
| 161 /** |
139 * A representation of an instance of a Dart class. | 162 * A representation of an instance of a Dart class. |
140 */ | 163 */ |
141 class DartObjectImpl implements DartObject { | 164 class DartObjectImpl implements DartObject { |
142 /** | 165 /** |
143 * An empty list of objects. | 166 * An empty list of objects. |
144 */ | 167 */ |
145 static const List<DartObjectImpl> EMPTY_LIST = const <DartObjectImpl>[]; | 168 static const List<DartObjectImpl> EMPTY_LIST = const <DartObjectImpl>[]; |
146 | 169 |
147 @override | 170 @override |
148 final ParameterizedType type; | 171 final ParameterizedType type; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 391 |
369 @override | 392 @override |
370 DartObject getField(String name) { | 393 DartObject getField(String name) { |
371 InstanceState state = _state; | 394 InstanceState state = _state; |
372 if (state is GenericState) { | 395 if (state is GenericState) { |
373 return state.fields[name]; | 396 return state.fields[name]; |
374 } | 397 } |
375 return null; | 398 return null; |
376 } | 399 } |
377 | 400 |
| 401 /// Gets the constructor that was called to create this value, if this is a |
| 402 /// const constructor invocation. Otherwise returns null. |
| 403 ConstructorInvocation getInvocation() { |
| 404 InstanceState state = _state; |
| 405 if (state is GenericState) { |
| 406 return state.invocation; |
| 407 } |
| 408 return null; |
| 409 } |
| 410 |
378 /** | 411 /** |
379 * Return the result of invoking the '>' operator on this object with the | 412 * Return the result of invoking the '>' operator on this object with the |
380 * [rightOperand]. The [typeProvider] is the type provider used to find known | 413 * [rightOperand]. The [typeProvider] is the type provider used to find known |
381 * types. | 414 * types. |
382 * | 415 * |
383 * Throws an [EvaluationException] if the operator is not appropriate for an | 416 * Throws an [EvaluationException] if the operator is not appropriate for an |
384 * object of this kind. | 417 * object of this kind. |
385 */ | 418 */ |
386 DartObjectImpl greaterThan( | 419 DartObjectImpl greaterThan( |
387 TypeProvider typeProvider, DartObjectImpl rightOperand) => | 420 TypeProvider typeProvider, DartObjectImpl rightOperand) => |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 */ | 1348 */ |
1316 static GenericState UNKNOWN_VALUE = | 1349 static GenericState UNKNOWN_VALUE = |
1317 new GenericState(new HashMap<String, DartObjectImpl>()); | 1350 new GenericState(new HashMap<String, DartObjectImpl>()); |
1318 | 1351 |
1319 /** | 1352 /** |
1320 * The values of the fields of this instance. | 1353 * The values of the fields of this instance. |
1321 */ | 1354 */ |
1322 final HashMap<String, DartObjectImpl> _fieldMap; | 1355 final HashMap<String, DartObjectImpl> _fieldMap; |
1323 | 1356 |
1324 /** | 1357 /** |
| 1358 * Information about the constructor invoked to generate this instance. |
| 1359 */ |
| 1360 final ConstructorInvocation invocation; |
| 1361 |
| 1362 /** |
1325 * Initialize a newly created state to represent a newly created object. The | 1363 * Initialize a newly created state to represent a newly created object. The |
1326 * [fieldMap] contains the values of the fields of the instance. | 1364 * [fieldMap] contains the values of the fields of the instance. |
1327 */ | 1365 */ |
1328 GenericState(this._fieldMap); | 1366 GenericState(this._fieldMap, {this.invocation}); |
1329 | 1367 |
1330 @override | 1368 @override |
1331 HashMap<String, DartObjectImpl> get fields => _fieldMap; | 1369 HashMap<String, DartObjectImpl> get fields => _fieldMap; |
1332 | 1370 |
1333 @override | 1371 @override |
1334 int get hashCode { | 1372 int get hashCode { |
1335 int hashCode = 0; | 1373 int hashCode = 0; |
1336 for (DartObjectImpl value in _fieldMap.values) { | 1374 for (DartObjectImpl value in _fieldMap.values) { |
1337 hashCode += value.hashCode; | 1375 hashCode += value.hashCode; |
1338 } | 1376 } |
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2808 return BoolState.from(_type == rightType); | 2846 return BoolState.from(_type == rightType); |
2809 } else if (rightOperand is DynamicState) { | 2847 } else if (rightOperand is DynamicState) { |
2810 return BoolState.UNKNOWN_VALUE; | 2848 return BoolState.UNKNOWN_VALUE; |
2811 } | 2849 } |
2812 return BoolState.FALSE_STATE; | 2850 return BoolState.FALSE_STATE; |
2813 } | 2851 } |
2814 | 2852 |
2815 @override | 2853 @override |
2816 String toString() => _type?.toString() ?? "-unknown-"; | 2854 String toString() => _type?.toString() ?? "-unknown-"; |
2817 } | 2855 } |
OLD | NEW |