Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: pkg/compiler/lib/src/resolution/resolution_result.dart

Issue 1170673002: Begin to compute constant expressions in resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix BinaryConstantExpression.getKnownType Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/resolution/resolution.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()';
+}
« no previous file with comments | « pkg/compiler/lib/src/resolution/resolution.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698