private Forest f;
private Node parent;
- private GSS.Phase phase;
- private Position reduction;
private HashSet<Node> children = new HashSet<Node>();
private boolean destroyed = false;
private int usedByNonDoomedNode = 0;
- public Position reduction() { return reduction; }
- public GSS.Phase phase() { return phase; }
+ public GSS.Phase phase() { return parent==null ? null : parent.phase(); }
public Forest getForest() { return f; }
public Node parent() { return parent; }
public void addChild(Node child) {
usedByNonDoomedNode += child.state().doomed ? 0 : 1;
}
public void removeChild(Node child) {
+ if (!children.contains(child)) return;
children.remove(child);
usedByNonDoomedNode -= child.state().doomed ? 0 : 1;
+ check();
}
public boolean usedByAnyNode() { return children.size() > 0; }
if (destroyed) return;
if (parent==null) return; // never destroy the "primordeal" result
destroyed = true;
- if (parent() != null) {
- parent().removeChild(this);
- parent().check();
- }
- OUTER: while(true) {
+ parent.removeChild(this);
+ while(children.size() > 0)
for(Node n : children) {
children.remove(n);
n.removeResult(this);
- n.check();
- continue OUTER;
+ break;
}
- break;
- }
}
public Result(Forest f, Node parent, Position reduction) {
+ this(f, parent, reduction, null);
+ }
+ public Result(Forest f, Node parent, Position reduction, GSS.Phase target) {
this.f = f;
- this.reduction = reduction;
this.parent = parent;
if (parent != null) parent.addChild(this);
- if (parent != null) phase = parent.phase();
+ if (reduction == null) return;
+ Parser.Table.State state0 = (Parser.Table.State)parent.state().gotoSetNonTerminals.get(reduction.owner());
+ target.newNodeFromReduction(this, state0, reduction);
}
// GraphViz //////////////////////////////////////////////////////////////////////////////