package jdk.nashorn.internal.runtime.regexp.joni;
@SuppressWarnings("javadoc")
public final class NodeOptInfo {
final MinMaxLen length = new MinMaxLen();
final OptAnchorInfo anchor = new OptAnchorInfo();
final OptExactInfo exb = new OptExactInfo();
final OptExactInfo exm = new OptExactInfo();
final OptExactInfo expr = new OptExactInfo();
final OptMapInfo map = new OptMapInfo();
public void setBoundNode(final MinMaxLen mmd) {
exb.mmd.copy(mmd);
expr.mmd.copy(mmd);
map.mmd.copy(mmd);
}
public void clear() {
length.clear();
anchor.clear();
exb.clear();
exm.clear();
expr.clear();
map.clear();
}
public void copy(final NodeOptInfo other) {
length.copy(other.length);
anchor.copy(other.anchor);
exb.copy(other.exb);
exm.copy(other.exm);
expr.copy(other.expr);
map.copy(other.map);
}
public void concatLeftNode(final NodeOptInfo other) {
final OptAnchorInfo tanchor = new OptAnchorInfo();
tanchor.concat(anchor, other.anchor, length.max, other.length.max);
anchor.copy(tanchor);
if (other.exb.length > 0 && length.max == 0) {
tanchor.concat(anchor, other.exb.anchor, length.max, other.length.max);
other.exb.anchor.copy(tanchor);
}
if (other.map.value > 0 && length.max == 0) {
if (other.map.mmd.max == 0) {
other.map.anchor.leftAnchor |= anchor.leftAnchor;
}
}
final boolean exbReach = exb.reachEnd;
final boolean exmReach = exm.reachEnd;
if (other.length.max != 0) {
exb.reachEnd = exm.reachEnd = false;
}
if (other.exb.length > 0) {
if (exbReach) {
exb.concat(other.exb);
other.exb.clear();
} else if (exmReach) {
exm.concat(other.exb);
other.exb.clear();
}
}
exm.select(other.exb);
exm.select(other.exm);
if (expr.length > 0) {
if (other.length.max > 0) {
int otherLengthMax = other.length.max;
if (otherLengthMax == MinMaxLen.INFINITE_DISTANCE) {
otherLengthMax = -1;
}
if (expr.length > otherLengthMax) {
expr.length = otherLengthMax;
}
if (expr.mmd.max == 0) {
exb.select(expr);
} else {
exm.select(expr);
}
}
} else if (other.expr.length > 0) {
expr.copy(other.expr);
}
map.select(other.map);
length.add(other.length);
}
public void altMerge(final NodeOptInfo other, final OptEnvironment env) {
anchor.altMerge(other.anchor);
exb.altMerge(other.exb, env);
exm.altMerge(other.exm, env);
expr.altMerge(other.expr, env);
map.altMerge(other.map);
length.altMerge(other.length);
}
public void setBound(final MinMaxLen mmd) {
exb.mmd.copy(mmd);
expr.mmd.copy(mmd);
map.mmd.copy(mmd);
}
}