Index: pkg/compiler/lib/src/resolution/resolution_result.dart |
diff --git a/pkg/compiler/lib/src/resolution/resolution_result.dart b/pkg/compiler/lib/src/resolution/resolution_result.dart |
index fd2344efcf5a188cee415c5f5ea2b730d0619aea..5426fe3f3de8c3af834007d4e70cbf1f51ddf341 100644 |
--- a/pkg/compiler/lib/src/resolution/resolution_result.dart |
+++ b/pkg/compiler/lib/src/resolution/resolution_result.dart |
@@ -4,44 +4,83 @@ |
part of resolution; |
+enum ResultKind { |
+ NONE, |
+ ELEMENT, |
+ TYPE, |
+ ASSERT, |
+ CONSTANT, |
+} |
+ |
/// The result of resolving a node. |
abstract class ResolutionResult { |
- Element get element; |
+ const ResolutionResult(); |
+ |
+ // TODO(johnniwinther): Remove this factory constructor when `null` is never |
+ // passed as an element result. |
+ factory ResolutionResult.forElement(Element element) { |
+ return element != null ? new ElementResult(element) : const NoneResult(); |
+ } |
+ |
+ ResultKind get kind; |
+ Element get element => null; |
+ DartType get type => null; |
+ ConstantExpression get constant => null; |
+ bool get isConstant => false; |
} |
/// The result for the resolution of a node that points to an [Element]. |
-class ElementResult implements ResolutionResult { |
+class ElementResult extends ResolutionResult { |
final Element element; |
- // TODO(johnniwinther): Remove this factory constructor when `null` is never |
- // passed as an element result. |
- factory ElementResult(Element element) { |
- return element != null ? new ElementResult.internal(element) : null; |
- } |
+ ResultKind get kind => ResultKind.ELEMENT; |
- ElementResult.internal(this.element); |
+ ElementResult(this.element); |
String toString() => 'ElementResult($element)'; |
} |
/// The result for the resolution of a node that points to an [DartType]. |
-class TypeResult implements ResolutionResult { |
+class TypeResult extends ResolutionResult { |
final DartType type; |
TypeResult(this.type) { |
assert(type != null); |
} |
+ ResultKind get kind => ResultKind.TYPE; |
+ |
Element get element => type.element; |
String toString() => 'TypeResult($type)'; |
} |
/// The result for the resolution of the `assert` method. |
-class AssertResult implements ResolutionResult { |
+class AssertResult extends ResolutionResult { |
const AssertResult(); |
- Element get element => null; |
+ ResultKind get kind => ResultKind.ASSERT; |
String toString() => 'AssertResult()'; |
} |
+ |
+class ConstantResult extends ResolutionResult { |
+ final Node node; |
+ final ConstantExpression constant; |
+ |
+ ConstantResult(this.node, this.constant); |
+ |
+ bool get isConstant => true; |
+ |
+ ResultKind get kind => ResultKind.CONSTANT; |
+ |
+ String toString() => 'ConstantResult(${constant.getText()})'; |
+} |
+ |
+class NoneResult extends ResolutionResult { |
+ const NoneResult(); |
+ |
+ ResultKind get kind => ResultKind.NONE; |
+ |
+ String toString() => 'NoneResult()'; |
+} |