for (Edge<Statement,VariableFilter> e : graph.getOutEdges(vs))
graph.addEdge(pred, e.getTo(), e.getData()); // XXX: ok to lose some edge info?
graph.removeNode(vs);
}
} else if (graph.getOutEdges(vs).size() == 1) {
Statement succ = graph.getOutEdges(vs).iterator().next().getTo();
if (graph.getInEdges(succ).size()==1) { // TODO: copy propagation could be improved by not requiring "no other predecessors"
// variable assignment with unique successor node that has no other predecessors - bypass this assignment
final Variable vsrc = vs.getSource();
succ.visitBy(new StatementVisitor() {
public void visitAnalyzeStm(AnalyzeStm s) {
s.setBase(vsrc);
}
public void visitGapifyStm(GapifyStm s) {
s.setBase(vsrc);
}
public void visitGetStm(GetStm s) {
s.setBase(vsrc);
}
public void visitRemoveStm(RemoveStm s) {
s.setBase(vsrc);
}
public void visitValidateStm(ValidateStm s) {
if (s.getBase() != null)
s.setBase(vsrc);
}
public void visitVarStm(VarStm s) {
s.setSource(vsrc);
}
public void visitPlugStm(PlugStm s) {
s.setBase(vsrc);
if (s.getXMLSource() != null)
s.setXMLSource(vsrc);
}
public void visitCheckStm(CheckStm s) {
if (s.getBase() != null)
s.setBase(vsrc);
}
public void visitSetStm(SetStm s) {
s.setBase(vsrc);
if (s.getXMLSource() != null)
s.setXMLSource(vsrc);
}
public void visitInsertStm(InsertStm s) {
s.setBase(vsrc);
if (s.getXMLSource() != null)
s.setXMLSource(vsrc);
}
public void visitConcatStm(ConcatStm s) {
s.setXMLSource(vsrc);
}
public void visitCopyStm(CopyStm s) {
s.setBase(vsrc);
if (s.getFirstChild() != null)
s.setFirstChild(vsrc);
if (s.getFirstAttr() != null)
s.setFirstAttr(vsrc);
if (s.getNextNode() != null)
s.setNextNode(vsrc);
}
public void visitCastStm(CastStm s) {
s.setBase(vsrc);
}
public void visitNodeStm(NodeStm s) {
if (s.getFirstChild() != null)
s.setFirstChild(vsrc);
if (s.getFirstAttr() != null)
s.setFirstAttr(vsrc);
if (s.getNextNode() != null)
s.setNextNode(vsrc);
}
// unreachable cases (these nodes cannot be def-use graph successors)
public void visitConstStm(ConstStm s) {}
public void visitEmptyStm(EmptyStm s) {}
public void visitNopStm(NopStm s) {}
public void visitUnknownStm(UnknownStm s) {}
// not in this phase
public void visitArrayReadStm(ArrayReadStm s) {
}
public void visitArrayWriteStm(ArrayWriteStm s) {
}
public void visitCallStm(CallStm s) {
}
public void visitEscapeStm(EscapeStm s) {
}
public void visitArrayWriteStringStm(ArrayWriteStringStm s) {
}
});
for (Edge<Statement,VariableFilter> e : graph.getInEdges(vs))
graph.addEdge(e.getFrom(), succ, e.getData()); // XXX: ok to lose some edge info?
graph.removeNode(vs);
}
}
}
}
// find unreachable nodes
Set<Statement> reachable = new HashSet<Statement>(graph.getEntries());
LinkedList<Statement> queue = new LinkedList<Statement>(graph.getEntries());
while (!queue.isEmpty()) {
Statement stm = queue.removeFirst();
for (Edge<Statement,VariableFilter> edge : graph.getOutEdges(stm)) {
if (!reachable.contains(edge.getTo())) {
reachable.add(edge.getTo());
queue.add(edge.getTo());
}
}
}
// find used nodes
Set<Statement> used = new HashSet<Statement>();
queue.clear();
for (Statement stm : graph.getNodes()) {
if (XMLGraphChecker.isStatementChecked(stm)) {
queue.add(stm);
used.add(stm);
}
}
while (!queue.isEmpty()) {
Statement stm = queue.removeFirst();
for (Edge<Statement,VariableFilter> edge : graph.getInEdges(stm)) {
if (!used.contains(edge.getFrom())) {
used.add(edge.getFrom());
queue.add(edge.getFrom());
}