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

Unified Diff: pkg/compiler/lib/src/constants/values.dart

Issue 1121233002: Add ConstantExpression.evaluate. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 5 years, 7 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/constants/expressions.dart ('k') | pkg/compiler/lib/src/core_types.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/constants/values.dart
diff --git a/pkg/compiler/lib/src/constants/values.dart b/pkg/compiler/lib/src/constants/values.dart
index 45f47eaa97786b523a70e2d9256d1ace360e1627..e40a6b838ac1dea110fc78cdacc932f3dbfa99e5 100644
--- a/pkg/compiler/lib/src/constants/values.dart
+++ b/pkg/compiler/lib/src/constants/values.dart
@@ -39,6 +39,9 @@ abstract class ConstantValueVisitor<R, A> {
abstract class ConstantValue {
const ConstantValue();
+ /// `true` if this is a valid constant value.
+ bool get isConstant => true;
+
bool get isNull => false;
bool get isBool => false;
bool get isTrue => false;
@@ -482,9 +485,11 @@ class ListConstantValue extends ObjectConstantValue {
String toStructuredString() {
StringBuffer sb = new StringBuffer();
- sb.write('ListConstant([');
+ sb.write('ListConstant(');
+ _unparseTypeArguments(sb);
+ sb.write('[');
for (int i = 0 ; i < length ; i++) {
- if (i > 0) sb.write(',');
+ if (i > 0) sb.write(', ');
sb.write(entries[i].toStructuredString());
}
sb.write('])');
@@ -551,11 +556,13 @@ class MapConstantValue extends ObjectConstantValue {
String toStructuredString() {
StringBuffer sb = new StringBuffer();
- sb.write('MapConstant({');
+ sb.write('MapConstant(');
+ _unparseTypeArguments(sb);
+ sb.write('{');
for (int i = 0; i < length; i++) {
- if (i > 0) sb.write(',');
+ if (i > 0) sb.write(', ');
sb.write(keys[i].toStructuredString());
- sb.write(':');
+ sb.write(': ');
sb.write(values[i].toStructuredString());
}
sb.write('})');
@@ -717,3 +724,27 @@ class DeferredConstantValue extends ConstantValue {
String toStructuredString() => 'DeferredConstant($referenced)';
}
+
+/// A constant value resulting from a non constant or erroneous constant
+/// expression.
+// TODO(johnniwinther): Expand this to contain the error kind.
+class NonConstantValue extends ConstantValue {
+ bool get isConstant => false;
+
+ @override
+ accept(ConstantValueVisitor visitor, arg) {
+ // TODO(johnniwinther): Should this be part of the visiting?
+ }
+
+ @override
+ List<ConstantValue> getDependencies() => const <ConstantValue>[];
+
+ @override
+ DartType getType(CoreTypes types) => const DynamicType();
+
+ @override
+ String toStructuredString() => 'NonConstant';
+
+ @override
+ String unparse() => '>>non-constant<<';
+}
« no previous file with comments | « pkg/compiler/lib/src/constants/expressions.dart ('k') | pkg/compiler/lib/src/core_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698