OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 part of resolution; | 5 part of resolution; |
6 | 6 |
7 enum ResultKind { | 7 enum ResultKind { |
8 NONE, | 8 NONE, |
9 ELEMENT, | 9 ELEMENT, |
10 TYPE, | 10 TYPE, |
11 ASSERT, | 11 ASSERT, |
12 CONSTANT, | 12 CONSTANT, |
| 13 PREFIX, |
13 } | 14 } |
14 | 15 |
15 /// The result of resolving a node. | 16 /// The result of resolving a node. |
16 abstract class ResolutionResult { | 17 abstract class ResolutionResult { |
17 const ResolutionResult(); | 18 const ResolutionResult(); |
18 | 19 |
19 // TODO(johnniwinther): Remove this factory constructor when `null` is never | 20 // TODO(johnniwinther): Remove this factory constructor when `null` is never |
20 // passed as an element result. | 21 // passed as an element result. |
21 factory ResolutionResult.forElement(Element element) { | 22 factory ResolutionResult.forElement(Element element) { |
22 return element != null ? new ElementResult(element) : const NoneResult(); | 23 return element != null ? new ElementResult(element) : const NoneResult(); |
23 } | 24 } |
24 | 25 |
25 ResultKind get kind; | 26 ResultKind get kind; |
26 Node get node => null; | 27 Node get node => null; |
27 Element get element => null; | 28 Element get element => null; |
28 DartType get type => null; | 29 DartType get type => null; |
29 ConstantExpression get constant => null; | 30 ConstantExpression get constant => null; |
30 bool get isConstant => false; | 31 bool get isConstant => false; |
31 } | 32 } |
32 | 33 |
| 34 /// The prefix of top level or member access, like `prefix.member`, |
| 35 /// `prefix.Class.member` or `Class.member`. |
| 36 class PrefixResult extends ResolutionResult { |
| 37 final PrefixElement prefix; |
| 38 final ClassElement cls; |
| 39 |
| 40 PrefixResult(this.prefix, this.cls); |
| 41 |
| 42 Element get element => cls != null ? cls : prefix; |
| 43 |
| 44 bool get isDeferred => prefix != null && prefix.isDeferred; |
| 45 |
| 46 ResultKind get kind => ResultKind.PREFIX; |
| 47 |
| 48 String toString() => 'PrefixResult($prefix,$cls)'; |
| 49 } |
| 50 |
33 /// The result for the resolution of a node that points to an [Element]. | 51 /// The result for the resolution of a node that points to an [Element]. |
34 class ElementResult extends ResolutionResult { | 52 class ElementResult extends ResolutionResult { |
35 final Element element; | 53 final Element element; |
36 | 54 |
37 ResultKind get kind => ResultKind.ELEMENT; | 55 ResultKind get kind => ResultKind.ELEMENT; |
38 | 56 |
39 ElementResult(this.element); | 57 ElementResult(this.element) { |
| 58 assert(element != null); |
| 59 } |
40 | 60 |
41 String toString() => 'ElementResult($element)'; | 61 String toString() => 'ElementResult($element)'; |
42 } | 62 } |
43 | 63 |
44 /// The result for the resolution of a node that points to an [DartType]. | 64 /// The result for the resolution of a node that points to an [DartType]. |
45 class TypeResult extends ResolutionResult { | 65 class TypeResult extends ResolutionResult { |
46 final DartType type; | 66 final DartType type; |
47 | 67 |
48 TypeResult(this.type) { | 68 TypeResult(this.type) { |
49 assert(type != null); | 69 assert(type != null); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 130 |
111 /// Returns the list of [ConstantExpression]s for each of the arguments. If | 131 /// Returns the list of [ConstantExpression]s for each of the arguments. If |
112 /// [isValidAsConstant] is `false`, `null` is returned. | 132 /// [isValidAsConstant] is `false`, `null` is returned. |
113 List<ConstantExpression> get constantArguments { | 133 List<ConstantExpression> get constantArguments { |
114 if (!isValidAsConstant) return null; | 134 if (!isValidAsConstant) return null; |
115 return argumentResults.map((ResolutionResult result) { | 135 return argumentResults.map((ResolutionResult result) { |
116 return result.constant; | 136 return result.constant; |
117 }).toList(); | 137 }).toList(); |
118 } | 138 } |
119 } | 139 } |
OLD | NEW |