extends Node<ResultNode>
implements Invokable<Pos, ResultNode, Object> {
- private boolean fromEmptyReduction;
private final Parser.Table.State state;
/** which GSS.Phase this StateNode belongs to */
public Parser.Table.State state() { return state; }
public boolean isDoomedState() { return state.doomed; }
+ public boolean hasPathToRoot() {
+ if (state.doomed) return false;
+ return super.hasPathToRoot();
+ }
public void check() {
if (destroyed) return;
// - be on the frontier or
// - have a non-doomed node closer to the frontier than themself
if (phase().isFrontier()) dead = false;
- else for(ResultNode r : successors)
+ else for(ResultNode r : successors())
if (state.doomed) { if (r.hasSuccessors()) { dead = false; break; } }
else { if (r.hasNonDoomedSuccessors()) { dead = false; break; } }
- dead |= predecessors.size()==0;
+ dead |= !hasPredecessors();
if (!dead) return;
if (phase() != null && phase().hash != null)
phase().hash.remove(state, predecessorPhase());
phase().newNodeFromReduction(r.rewrite(region), r, this);
} else {
// never start reductions at a node that was created via a right-nulled rule
- if (only.reduction().numPops()==0) return;
+ if (only.reduction() != null && only.reduction().numPops()==0) return;
reduce(r, r.numPops()-1, phase(), only);
}
}
private void reduce(Pos r, int pos, GSS.Phase target, ResultNode only) {
- for(ResultNode res : predecessors)
+ for(ResultNode res : this)
if (only == null || res == only)
for(StateNode pred : res) {
Forest[] holder = r.holder;
Forest old = pos >= holder.length ? null : holder[pos];
if (pos < holder.length) holder[pos] = res.getForest();
if (pos>0) pred.reduce(r, pos-1, target, null);
- else {
- Input.Region region = pred.phase().getLocation().createRegion(target.getLocation());
- new Reduction(pred, r, r.rewrite(region), target);
- }
+ else new Reduction(pred, r,
+ pred.hasPathToRoot()
+ ? r.rewrite(pred.phase().getLocation().createRegion(target.getLocation()))
+ : null,
+ target);
if (pos < holder.length) holder[pos] = old;
}
}
StateNode(GSS.Phase phase, ResultNode pred, State state) {
super(phase, pred.phase());
this.state = state;
- this.fromEmptyReduction = pred!=null && pred.reduction()!=null && pred.reduction().numPops()==0;
if (phase.hash.get(state, pred.phase()) != null) throw new Error("severe problem!");
phase.hash.put(state, pred.phase(), this);
addPred(pred);
// Add/Remove Successors/Predecessors //////////////////////////////////////////////////////////////////////////////
public void addPred(Forest f, Pos reduction, StateNode pred) {
- for(ResultNode r : predecessors)
+ for(ResultNode r : this)
if (r.predecessorsContains(pred)) {
r.merge(f);
return;