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

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

Issue 2199593003: Add kind to ConstantValue. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebased Created 4 years, 4 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 | « no previous file | pkg/compiler/lib/src/js_backend/constant_emitter.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 fbda202d80ea6108baf3ea492872fc8ec2554ea6..cba4e69155ba8949bf1cbc55a3955291eb781654 100644
--- a/pkg/compiler/lib/src/constants/values.dart
+++ b/pkg/compiler/lib/src/constants/values.dart
@@ -12,6 +12,23 @@ import '../elements/elements.dart'
import '../tree/dartstring.dart';
import '../util/util.dart' show Hashing;
+enum ConstantValueKind {
+ FUNCTION,
+ NULL,
+ INT,
+ DOUBLE,
+ BOOL,
+ STRING,
+ LIST,
+ MAP,
+ CONSTRUCTED,
+ TYPE,
+ INTERCEPTOR,
+ SYNTHETIC,
+ DEFERRED,
+ NON_CONSTANT,
+}
+
abstract class ConstantValueVisitor<R, A> {
const ConstantValueVisitor();
@@ -84,6 +101,8 @@ abstract class ConstantValue {
/// Returns a structured representation of this constant suited for debugging.
String toStructuredText();
+ ConstantValueKind get kind;
+
String toString() {
assertDebugMode("Use ConstantValue.toDartText() or "
"ConstantValue.toStructuredText() "
@@ -118,6 +137,8 @@ class FunctionConstantValue extends ConstantValue {
accept(ConstantValueVisitor visitor, arg) => visitor.visitFunction(this, arg);
+ ConstantValueKind get kind => ConstantValueKind.FUNCTION;
+
String toDartText() {
if (element.isStatic) {
return '${element.enclosingClass.name}.${element.name}';
@@ -177,6 +198,8 @@ class NullConstantValue extends PrimitiveConstantValue {
accept(ConstantValueVisitor visitor, arg) => visitor.visitNull(this, arg);
+ ConstantValueKind get kind => ConstantValueKind.NULL;
+
String toStructuredText() => 'NullConstant';
}
@@ -258,6 +281,8 @@ class IntConstantValue extends NumConstantValue {
accept(ConstantValueVisitor visitor, arg) => visitor.visitInt(this, arg);
+ ConstantValueKind get kind => ConstantValueKind.INT;
+
String toStructuredText() => 'IntConstant(${toDartText()})';
}
@@ -320,6 +345,8 @@ class DoubleConstantValue extends NumConstantValue {
accept(ConstantValueVisitor visitor, arg) => visitor.visitDouble(this, arg);
+ ConstantValueKind get kind => ConstantValueKind.DOUBLE;
+
String toStructuredText() => 'DoubleConstant(${toDartText()})';
}
@@ -338,6 +365,8 @@ abstract class BoolConstantValue extends PrimitiveConstantValue {
accept(ConstantValueVisitor visitor, arg) => visitor.visitBool(this, arg);
+ ConstantValueKind get kind => ConstantValueKind.BOOL;
+
String toStructuredText() => 'BoolConstant(${toDartText()})';
}
@@ -414,6 +443,8 @@ class StringConstantValue extends PrimitiveConstantValue {
accept(ConstantValueVisitor visitor, arg) => visitor.visitString(this, arg);
+ ConstantValueKind get kind => ConstantValueKind.STRING;
+
// TODO(johnniwinther): Ensure correct escaping.
String toDartText() => '"${primitiveValue.slowToString()}"';
@@ -457,6 +488,8 @@ class TypeConstantValue extends ObjectConstantValue {
accept(ConstantValueVisitor visitor, arg) => visitor.visitType(this, arg);
+ ConstantValueKind get kind => ConstantValueKind.TYPE;
+
String toDartText() => '$representedType';
String toStructuredText() => 'TypeConstant(${representedType})';
@@ -492,6 +525,8 @@ class ListConstantValue extends ObjectConstantValue {
accept(ConstantValueVisitor visitor, arg) => visitor.visitList(this, arg);
+ ConstantValueKind get kind => ConstantValueKind.LIST;
+
String toDartText() {
StringBuffer sb = new StringBuffer();
_unparseTypeArguments(sb);
@@ -567,6 +602,8 @@ class MapConstantValue extends ObjectConstantValue {
accept(ConstantValueVisitor visitor, arg) => visitor.visitMap(this, arg);
+ ConstantValueKind get kind => ConstantValueKind.MAP;
+
String toDartText() {
StringBuffer sb = new StringBuffer();
_unparseTypeArguments(sb);
@@ -621,6 +658,8 @@ class InterceptorConstantValue extends ConstantValue {
DartType getType(CoreTypes types) => const DynamicType();
+ ConstantValueKind get kind => ConstantValueKind.INTERCEPTOR;
+
String toDartText() {
return 'interceptor($dispatchedType)';
}
@@ -632,9 +671,9 @@ class InterceptorConstantValue extends ConstantValue {
class SyntheticConstantValue extends ConstantValue {
final payload;
- final kind;
+ final valueKind;
- SyntheticConstantValue(this.kind, this.payload);
+ SyntheticConstantValue(this.valueKind, this.payload);
bool get isDummy => true;
@@ -642,7 +681,7 @@ class SyntheticConstantValue extends ConstantValue {
return other is SyntheticConstantValue && payload == other.payload;
}
- get hashCode => payload.hashCode * 17 + kind.hashCode;
+ get hashCode => payload.hashCode * 17 + valueKind.hashCode;
List<ConstantValue> getDependencies() => const <ConstantValue>[];
@@ -652,9 +691,11 @@ class SyntheticConstantValue extends ConstantValue {
DartType getType(CoreTypes types) => const DynamicType();
- String toDartText() => 'synthetic($kind, $payload)';
+ ConstantValueKind get kind => ConstantValueKind.SYNTHETIC;
- String toStructuredText() => 'SyntheticConstant($kind, $payload)';
+ String toDartText() => 'synthetic($valueKind, $payload)';
+
+ String toStructuredText() => 'SyntheticConstant($valueKind, $payload)';
}
class ConstructedConstantValue extends ObjectConstantValue {
@@ -693,6 +734,8 @@ class ConstructedConstantValue extends ObjectConstantValue {
return visitor.visitConstructed(this, arg);
}
+ ConstantValueKind get kind => ConstantValueKind.CONSTRUCTED;
+
String toDartText() {
StringBuffer sb = new StringBuffer();
sb.write(type.name);
@@ -752,6 +795,8 @@ class DeferredConstantValue extends ConstantValue {
DartType getType(CoreTypes types) => referenced.getType(types);
+ ConstantValueKind get kind => ConstantValueKind.DEFERRED;
+
String toDartText() => 'deferred(${referenced.toDartText()})';
String toStructuredText() {
@@ -776,6 +821,8 @@ class NonConstantValue extends ConstantValue {
@override
DartType getType(CoreTypes types) => const DynamicType();
+ ConstantValueKind get kind => ConstantValueKind.NON_CONSTANT;
+
@override
String toStructuredText() => 'NonConstant';
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/constant_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698