Обход TuplePattern

This commit is contained in:
Victor 2016-07-22 21:43:23 +03:00
parent 4ac0943805
commit 839f571b2c

View File

@ -266,6 +266,28 @@ public abstract class OptimizationVisitor<T> implements ResultVisitor<Node, T> {
} }
} }
if (pattern instanceof MatchExpression.TuplePattern) {
final MatchExpression.TuplePattern tuple = (MatchExpression.TuplePattern) pattern;
final List<Expression> newValues = new ArrayList<>(tuple.values.size());
boolean valuesChanged = false;
for (Expression value : tuple.values) {
final Node node = value.accept(this, t);
if (node != value) {
valuesChanged = true;
value = (Expression) node;
}
newValues.add(value);
}
if (valuesChanged) {
changed = true;
final Expression optCondition = pattern.optCondition;
final Statement result = pattern.result;
pattern = new MatchExpression.TuplePattern(newValues);
pattern.optCondition = optCondition;
pattern.result = result;
}
}
final Node patternResult = pattern.result.accept(this, t); final Node patternResult = pattern.result.accept(this, t);
if (patternResult != pattern.result) { if (patternResult != pattern.result) {
changed = true; changed = true;