Revisit existing constants in the constants transformer.

Unevaluated constants are re-evaluated, and evaluated constants are
re-canonicalized.

Change-Id: I241f6b5d734797101ab1168746a849713c104695
Reviewed-on: https://dart-review.googlesource.com/c/91230
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
This commit is contained in:
Aske Simon Christensen 2019-01-29 10:36:12 +00:00 committed by commit-bot@chromium.org
parent 97cb74cf63
commit 219a2fcf66

View file

@ -348,6 +348,17 @@ class ConstantsTransformer extends Transformer {
return super.visitStaticInvocation(node);
}
visitConstantExpression(ConstantExpression node) {
Constant constant = node.constant;
if (constant is UnevaluatedConstant) {
Expression expression = constant.expression;
return tryEvaluateAndTransformWithContext(expression, expression);
} else {
node.constant = constantEvaluator.canonicalize(constant);
return node;
}
}
tryEvaluateAndTransformWithContext(TreeNode treeContext, Expression node) {
final Constant constant = tryEvaluateWithContext(treeContext, node);
return constant != null ? new ConstantExpression(constant) : node;