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

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

Issue 1148343004: Remove ConstantExpression.value (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update 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/constructors.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/constants/expressions.dart
diff --git a/pkg/compiler/lib/src/constants/expressions.dart b/pkg/compiler/lib/src/constants/expressions.dart
index 32c678984d3bcbbc2d6db039965031bcace59e40..23d65f295ea6b880d9ae3699a9cfe3cb64e68d56 100644
--- a/pkg/compiler/lib/src/constants/expressions.dart
+++ b/pkg/compiler/lib/src/constants/expressions.dart
@@ -261,11 +261,6 @@ abstract class ConstantExpression {
ConstantExpressionKind get kind;
- /// Returns the value of this constant expression.
- // TODO(johnniwinther): Replace this with an evaluation method that takes
- // a constant system and an environment.
- ConstantValue get value;
-
// TODO(johnniwinther): Unify precedence handled between constants, front-end
// and back-end.
int get precedence => 16;
@@ -314,8 +309,6 @@ abstract class ConstantExpression {
/// A synthetic constant used to recover from errors.
class ErroneousConstantExpression extends ConstantExpression {
- final PrimitiveConstantValue value = new NullConstantValue();
-
ConstantExpressionKind get kind => ConstantExpressionKind.ERRONEOUS;
accept(ConstantExpressionVisitor visitor, [context]) {
@@ -326,7 +319,7 @@ class ErroneousConstantExpression extends ConstantExpression {
ConstantValue evaluate(Environment environment,
ConstantSystem constantSystem) {
// TODO(johnniwinther): Use non-constant values for errors.
- return value;
+ return new NonConstantValue();
}
@override
@@ -338,10 +331,6 @@ class ErroneousConstantExpression extends ConstantExpression {
/// A boolean, int, double, string, or null constant.
abstract class PrimitiveConstantExpression extends ConstantExpression {
- final PrimitiveConstantValue value;
-
- PrimitiveConstantExpression(this.value);
-
/// The primitive value of this contant expression.
get primitiveValue;
}
@@ -350,8 +339,7 @@ abstract class PrimitiveConstantExpression extends ConstantExpression {
class BoolConstantExpression extends PrimitiveConstantExpression {
final bool primitiveValue;
- BoolConstantExpression(this.primitiveValue,
- PrimitiveConstantValue value) : super(value);
+ BoolConstantExpression(this.primitiveValue);
ConstantExpressionKind get kind => ConstantExpressionKind.BOOL;
@@ -378,8 +366,7 @@ class BoolConstantExpression extends PrimitiveConstantExpression {
class IntConstantExpression extends PrimitiveConstantExpression {
final int primitiveValue;
- IntConstantExpression(this.primitiveValue,
- PrimitiveConstantValue value) : super(value);
+ IntConstantExpression(this.primitiveValue);
ConstantExpressionKind get kind => ConstantExpressionKind.INT;
@@ -406,8 +393,7 @@ class IntConstantExpression extends PrimitiveConstantExpression {
class DoubleConstantExpression extends PrimitiveConstantExpression {
final double primitiveValue;
- DoubleConstantExpression(this.primitiveValue,
- PrimitiveConstantValue value) : super(value);
+ DoubleConstantExpression(this.primitiveValue);
ConstantExpressionKind get kind => ConstantExpressionKind.DOUBLE;
@@ -434,8 +420,7 @@ class DoubleConstantExpression extends PrimitiveConstantExpression {
class StringConstantExpression extends PrimitiveConstantExpression {
final String primitiveValue;
- StringConstantExpression(this.primitiveValue,
- PrimitiveConstantValue value) : super(value);
+ StringConstantExpression(this.primitiveValue);
ConstantExpressionKind get kind => ConstantExpressionKind.STRING;
@@ -460,7 +445,7 @@ class StringConstantExpression extends PrimitiveConstantExpression {
/// Null literal constant.
class NullConstantExpression extends PrimitiveConstantExpression {
- NullConstantExpression(PrimitiveConstantValue value) : super(value);
+ NullConstantExpression();
ConstantExpressionKind get kind => ConstantExpressionKind.NULL;
@@ -485,11 +470,10 @@ class NullConstantExpression extends PrimitiveConstantExpression {
/// Literal list constant.
class ListConstantExpression extends ConstantExpression {
- final ListConstantValue value;
final InterfaceType type;
final List<ConstantExpression> values;
- ListConstantExpression(this.value, this.type, this.values);
+ ListConstantExpression(this.type, this.values);
ConstantExpressionKind get kind => ConstantExpressionKind.LIST;
@@ -505,8 +489,8 @@ class ListConstantExpression extends ConstantExpression {
}
ConstantExpression apply(NormalizedArguments arguments) {
- return new ListConstantExpression(null, type,
- values.map((v) => v.apply(arguments)).toList());
+ return new ListConstantExpression(
+ type, values.map((v) => v.apply(arguments)).toList());
}
@override
@@ -531,12 +515,11 @@ class ListConstantExpression extends ConstantExpression {
/// Literal map constant.
class MapConstantExpression extends ConstantExpression {
- final MapConstantValue value;
final InterfaceType type;
final List<ConstantExpression> keys;
final List<ConstantExpression> values;
- MapConstantExpression(this.value, this.type, this.keys, this.values);
+ MapConstantExpression(this.type, this.keys, this.values);
ConstantExpressionKind get kind => ConstantExpressionKind.MAP;
@@ -554,7 +537,8 @@ class MapConstantExpression extends ConstantExpression {
}
ConstantExpression apply(NormalizedArguments arguments) {
- return new MapConstantExpression(null, type,
+ return new MapConstantExpression(
+ type,
keys.map((k) => k.apply(arguments)).toList(),
values.map((v) => v.apply(arguments)).toList());
}
@@ -582,14 +566,12 @@ class MapConstantExpression extends ConstantExpression {
/// Invocation of a const constructor.
class ConstructedConstantExpression extends ConstantExpression {
- final ConstantValue value;
final InterfaceType type;
final ConstructorElement target;
final CallStructure callStructure;
final List<ConstantExpression> arguments;
ConstructedConstantExpression(
- this.value,
this.type,
this.target,
this.callStructure,
@@ -614,7 +596,7 @@ class ConstructedConstantExpression extends ConstantExpression {
}
ConstructedConstantExpression apply(NormalizedArguments arguments) {
- return new ConstructedConstantExpression(null,
+ return new ConstructedConstantExpression(
type, target, callStructure,
this.arguments.map((a) => a.apply(arguments)).toList());
}
@@ -657,10 +639,9 @@ class ConstructedConstantExpression extends ConstantExpression {
/// String literal with juxtaposition and/or interpolations.
class ConcatenateConstantExpression extends ConstantExpression {
- final StringConstantValue value;
final List<ConstantExpression> expressions;
- ConcatenateConstantExpression(this.value, this.expressions);
+ ConcatenateConstantExpression(this.expressions);
ConstantExpressionKind get kind => ConstantExpressionKind.CONCATENATE;
@@ -669,7 +650,7 @@ class ConcatenateConstantExpression extends ConstantExpression {
}
ConstantExpression apply(NormalizedArguments arguments) {
- return new ConcatenateConstantExpression(null,
+ return new ConcatenateConstantExpression(
expressions.map((a) => a.apply(arguments)).toList());
}
@@ -722,10 +703,9 @@ class ConcatenateConstantExpression extends ConstantExpression {
/// Symbol literal.
class SymbolConstantExpression extends ConstantExpression {
- final ConstructedConstantValue value;
final String name;
- SymbolConstantExpression(this.value, this.name);
+ SymbolConstantExpression(this.name);
ConstantExpressionKind get kind => ConstantExpressionKind.SYMBOL;
@@ -751,11 +731,10 @@ class SymbolConstantExpression extends ConstantExpression {
/// Type literal.
class TypeConstantExpression extends ConstantExpression {
- final TypeConstantValue value;
/// Either [DynamicType] or a raw [GenericType].
final DartType type;
- TypeConstantExpression(this.value, this.type) {
+ TypeConstantExpression(this.type) {
assert(type is GenericType || type is DynamicType);
}
@@ -782,10 +761,9 @@ class TypeConstantExpression extends ConstantExpression {
/// Reference to a constant local, top-level, or static variable.
class VariableConstantExpression extends ConstantExpression {
- final ConstantValue value;
final VariableElement element;
- VariableConstantExpression(this.value, this.element);
+ VariableConstantExpression(this.element);
ConstantExpressionKind get kind => ConstantExpressionKind.VARIABLE;
@@ -810,10 +788,9 @@ class VariableConstantExpression extends ConstantExpression {
/// Reference to a top-level or static function.
class FunctionConstantExpression extends ConstantExpression {
- final FunctionConstantValue value;
final FunctionElement element;
- FunctionConstantExpression(this.value, this.element);
+ FunctionConstantExpression(this.element);
ConstantExpressionKind get kind => ConstantExpressionKind.FUNCTION;
@@ -838,12 +815,11 @@ class FunctionConstantExpression extends ConstantExpression {
/// A constant binary expression like `a * b`.
class BinaryConstantExpression extends ConstantExpression {
- final ConstantValue value;
final ConstantExpression left;
final BinaryOperator operator;
final ConstantExpression right;
- BinaryConstantExpression(this.value, this.left, this.operator, this.right) {
+ BinaryConstantExpression(this.left, this.operator, this.right) {
assert(PRECEDENCE_MAP[operator.kind] != null);
}
@@ -863,7 +839,6 @@ class BinaryConstantExpression extends ConstantExpression {
ConstantExpression apply(NormalizedArguments arguments) {
return new BinaryConstantExpression(
- value,
left.apply(arguments),
operator,
right.apply(arguments));
@@ -910,11 +885,10 @@ class BinaryConstantExpression extends ConstantExpression {
/// A constant identical invocation like `identical(a, b)`.
class IdenticalConstantExpression extends ConstantExpression {
- final ConstantValue value;
final ConstantExpression left;
final ConstantExpression right;
- IdenticalConstantExpression(this.value, this.left, this.right);
+ IdenticalConstantExpression(this.left, this.right);
ConstantExpressionKind get kind => ConstantExpressionKind.IDENTICAL;
@@ -932,7 +906,6 @@ class IdenticalConstantExpression extends ConstantExpression {
ConstantExpression apply(NormalizedArguments arguments) {
return new IdenticalConstantExpression(
- value,
left.apply(arguments),
right.apply(arguments));
}
@@ -954,11 +927,10 @@ class IdenticalConstantExpression extends ConstantExpression {
/// A unary constant expression like `-a`.
class UnaryConstantExpression extends ConstantExpression {
- final ConstantValue value;
final UnaryOperator operator;
final ConstantExpression expression;
- UnaryConstantExpression(this.value, this.operator, this.expression) {
+ UnaryConstantExpression(this.operator, this.expression) {
assert(PRECEDENCE_MAP[operator.kind] != null);
}
@@ -977,7 +949,6 @@ class UnaryConstantExpression extends ConstantExpression {
ConstantExpression apply(NormalizedArguments arguments) {
return new UnaryConstantExpression(
- value,
operator,
expression.apply(arguments));
}
@@ -1006,10 +977,9 @@ class UnaryConstantExpression extends ConstantExpression {
/// A string length constant expression like `a.length`.
class StringLengthConstantExpression extends ConstantExpression {
- final ConstantValue value;
final ConstantExpression expression;
- StringLengthConstantExpression(this.value, this.expression);
+ StringLengthConstantExpression(this.expression);
ConstantExpressionKind get kind => ConstantExpressionKind.STRING_LENGTH;
@@ -1029,9 +999,7 @@ class StringLengthConstantExpression extends ConstantExpression {
}
ConstantExpression apply(NormalizedArguments arguments) {
- return new StringLengthConstantExpression(
- value,
- expression.apply(arguments));
+ return new StringLengthConstantExpression(expression.apply(arguments));
}
int get precedence => 15;
@@ -1049,13 +1017,11 @@ class StringLengthConstantExpression extends ConstantExpression {
/// A constant conditional expression like `a ? b : c`.
class ConditionalConstantExpression extends ConstantExpression {
- final ConstantValue value;
final ConstantExpression condition;
final ConstantExpression trueExp;
final ConstantExpression falseExp;
- ConditionalConstantExpression(this.value,
- this.condition,
+ ConditionalConstantExpression(this.condition,
this.trueExp,
this.falseExp);
@@ -1067,7 +1033,6 @@ class ConditionalConstantExpression extends ConstantExpression {
ConstantExpression apply(NormalizedArguments arguments) {
return new ConditionalConstantExpression(
- value,
condition.apply(arguments),
trueExp.apply(arguments),
falseExp.apply(arguments));
@@ -1122,10 +1087,6 @@ class PositionalArgumentReference extends ConstantExpression {
return visitor.visitPositional(this, context);
}
- ConstantValue get value {
- throw new UnsupportedError('PositionalArgumentReference.value');
- }
-
ConstantExpression apply(NormalizedArguments arguments) {
return arguments.getPositionalArgument(index);
}
@@ -1157,10 +1118,6 @@ class NamedArgumentReference extends ConstantExpression {
return visitor.visitNamed(this, context);
}
- ConstantValue get value {
- throw new UnsupportedError('NamedArgumentReference.value');
- }
-
ConstantExpression apply(NormalizedArguments arguments) {
return arguments.getNamedArgument(name);
}
@@ -1179,11 +1136,10 @@ class NamedArgumentReference extends ConstantExpression {
}
abstract class FromEnvironmentConstantExpression extends ConstantExpression {
- final ConstantValue value;
final ConstantExpression name;
final ConstantExpression defaultValue;
- FromEnvironmentConstantExpression(this.value, this.name, this.defaultValue);
+ FromEnvironmentConstantExpression(this.name, this.defaultValue);
@override
int _computeHashCode() {
@@ -1203,10 +1159,9 @@ class BoolFromEnvironmentConstantExpression
extends FromEnvironmentConstantExpression {
BoolFromEnvironmentConstantExpression(
- ConstantValue value,
ConstantExpression name,
ConstantExpression defaultValue)
- : super(value, name, defaultValue);
+ : super(name, defaultValue);
ConstantExpressionKind get kind {
return ConstantExpressionKind.BOOL_FROM_ENVIRONMENT;
@@ -1245,7 +1200,6 @@ class BoolFromEnvironmentConstantExpression
ConstantExpression apply(NormalizedArguments arguments) {
return new BoolFromEnvironmentConstantExpression(
- null,
name.apply(arguments),
defaultValue != null ? defaultValue.apply(arguments) : null);
}
@@ -1256,10 +1210,9 @@ class IntFromEnvironmentConstantExpression
extends FromEnvironmentConstantExpression {
IntFromEnvironmentConstantExpression(
- ConstantValue value,
ConstantExpression name,
ConstantExpression defaultValue)
- : super(value, name, defaultValue);
+ : super(name, defaultValue);
ConstantExpressionKind get kind {
return ConstantExpressionKind.INT_FROM_ENVIRONMENT;
@@ -1300,7 +1253,6 @@ class IntFromEnvironmentConstantExpression
ConstantExpression apply(NormalizedArguments arguments) {
return new IntFromEnvironmentConstantExpression(
- null,
name.apply(arguments),
defaultValue != null ? defaultValue.apply(arguments) : null);
}
@@ -1311,10 +1263,9 @@ class StringFromEnvironmentConstantExpression
extends FromEnvironmentConstantExpression {
StringFromEnvironmentConstantExpression(
- ConstantValue value,
ConstantExpression name,
ConstantExpression defaultValue)
- : super(value, name, defaultValue);
+ : super(name, defaultValue);
ConstantExpressionKind get kind {
return ConstantExpressionKind.STRING_FROM_ENVIRONMENT;
@@ -1351,7 +1302,6 @@ class StringFromEnvironmentConstantExpression
ConstantExpression apply(NormalizedArguments arguments) {
return new StringFromEnvironmentConstantExpression(
- null,
name.apply(arguments),
defaultValue != null ? defaultValue.apply(arguments) : null);
}
@@ -1360,11 +1310,10 @@ class StringFromEnvironmentConstantExpression
/// A constant expression referenced with a deferred prefix.
/// For example `lib.C`.
class DeferredConstantExpression extends ConstantExpression {
- final ConstantValue value;
final ConstantExpression expression;
final PrefixElement prefix;
- DeferredConstantExpression(this.value, this.expression, this.prefix);
+ DeferredConstantExpression(this.expression, this.prefix);
ConstantExpressionKind get kind => ConstantExpressionKind.DEFERRED;
@@ -1381,7 +1330,7 @@ class DeferredConstantExpression extends ConstantExpression {
ConstantExpression apply(NormalizedArguments arguments) {
return new DeferredConstantExpression(
- value, expression.apply(arguments), prefix);
+ expression.apply(arguments), prefix);
}
@override
@@ -1572,7 +1521,20 @@ class ConstExpPrinter extends ConstantExpressionVisitor {
@override
void visitConcatenate(ConcatenateConstantExpression exp, [_]) {
- sb.write(exp.value.unparse());
+ sb.write('"');
+ for (ConstantExpression expression in exp.expressions) {
+ if (expression.kind == ConstantExpressionKind.STRING) {
+ StringConstantExpression string = expression;
+ // TODO(johnniwinther): Ensure correct escaping.
+ sb.write('${string.primitiveValue}');
+ } else {
+ sb.write(r"${");
+ visit(expression);
+ sb.write("}");
+ }
+
+ }
+ sb.write('"');
}
@override
« no previous file with comments | « pkg/compiler/lib/src/constants/constructors.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698