package jdk.nashorn.internal.runtime.regexp.joni.ast;
import jdk.nashorn.internal.runtime.regexp.joni.Option;
import jdk.nashorn.internal.runtime.regexp.joni.constants.EncloseType;
@SuppressWarnings("javadoc")
public final class EncloseNode extends StateNode implements EncloseType {
public final int type;
public int regNum;
public int option;
public Node target;
public int callAddr;
public int minLength;
public int maxLength;
public int charLength;
public int optCount;
public EncloseNode(final int type) {
this.type = type;
callAddr = -1;
}
public EncloseNode() {
this(MEMORY);
}
public EncloseNode(final int option, final int i) {
this(OPTION);
this.option = option;
}
@Override
public int getType() {
return ENCLOSE;
}
@Override
protected void setChild(final Node newChild) {
target = newChild;
}
@Override
protected Node getChild() {
return target;
}
public void setTarget(final Node tgt) {
target = tgt;
tgt.parent = this;
}
@Override
public String getName() {
return "Enclose";
}
@Override
public String toString(final int level) {
final StringBuilder value = new StringBuilder(super.toString(level));
value.append("\n type: ").append(typeToString());
value.append("\n regNum: ").append(regNum);
value.append("\n option: ").append(Option.toString(option));
value.append("\n target: ").append(pad(target, level + 1));
value.append("\n callAddr: ").append(callAddr);
value.append("\n minLength: ").append(minLength);
value.append("\n maxLength: ").append(maxLength);
value.append("\n charLength: ").append(charLength);
value.append("\n optCount: ").append(optCount);
return value.toString();
}
public String typeToString() {
final StringBuilder types = new StringBuilder();
if (isStopBacktrack()) types.append("STOP_BACKTRACK ");
if (isMemory()) types.append("MEMORY ");
if (isOption()) types.append("OPTION ");
return types.toString();
}
public boolean isMemory() {
return (type & MEMORY) != 0;
}
public boolean isOption() {
return (type & OPTION) != 0;
}
public boolean isStopBacktrack() {
return (type & STOP_BACKTRACK) != 0;
}
}