Skip to content

Commit

Permalink
simplify-range-rule keeps expr states if there is no simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Oct 10, 2024
1 parent bc9b87d commit 5f820be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ public Expression toExpression() {
for (int i = 1; i < sourceValues.size(); i++) {
result = mergeExprOp.apply(result, sourceValues.get(i).toExpression());
}
expr.transferState(result);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ public void setMutableState(String key, Object state) {
public int arity() {
return children.size();
}

public void transferState(AbstractTreeNode target) {
target.mutableState = mutableState.clone();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public interface MutableState {
<T> Optional<T> get(String key);

MutableState set(String key, Object value);
MutableState clone();

/** EmptyMutableState */
class EmptyMutableState implements MutableState {
Expand All @@ -50,6 +51,11 @@ public <T> Optional<T> get(String key) {
public MutableState set(String key, Object value) {
return new SingleMutableState(key, value);
}

@Override
public MutableState clone () {
return INSTANCE;
}
}

/** SingleMutableState */
Expand Down Expand Up @@ -80,6 +86,11 @@ public MutableState set(String key, Object value) {
multiMutableState.set(key, value);
return multiMutableState;
}

@Override
public MutableState clone() {
return new SingleMutableState(key, value);
}
}

/** MultiMutableState */
Expand All @@ -96,5 +107,14 @@ public MutableState set(String key, Object value) {
states.put(key, value);
return this;
}

@Override
public MutableState clone() {
MutableState target = new MultiMutableState();
for (String key : states.keySet()) {
target = target.set(key, states.get(key));
}
return target;
}
}
}

0 comments on commit 5f820be

Please sign in to comment.