Search in sources :

Example 1 with ReturnNode

use of com.jopdesign.common.code.ControlFlowGraph.ReturnNode in project jop by jop-devel.

the class SuperGraph method incomingEdgesOf.

/**
	 * The incoming edges are generated as follows:
	 * <ul>
	 * <li/>return node: superedge returning to the caller
	 * <li/>entry  node: superedge invoking the node's method
	 * <li/>other:       intraprocedural CFG edge
	 * </ul>
	 * @param node
	 * @return
	 */
public Iterable<SuperGraphEdge> incomingEdgesOf(SuperGraphNode node) {
    CFGNode cfgNode = node.getCFGNode();
    if (cfgNode instanceof ReturnNode) {
        /* return node: incoming edges are callgraph return edges */
        final ReturnNode retNode = (ReturnNode) cfgNode;
        Set<SuperEdge> cgReturnEdges = superGraph.incomingEdgesOf(node.getContextCFG());
        return new Filter<SuperGraphEdge>() {

            @Override
            protected boolean include(SuperGraphEdge e) {
                if (!(e instanceof SuperReturnEdge))
                    return false;
                SuperReturnEdge retEdge = (SuperReturnEdge) e;
                return retEdge.getReturnNode().equals(retNode);
            }
        }.<SuperGraphEdge>filter(cgReturnEdges);
    } else if (cfgNode instanceof VirtualNode && ((VirtualNode) cfgNode).getKind() == VirtualNodeKind.ENTRY) {
        /* entry  node: superedge invoking the node's method */
        Set<SuperEdge> cgInvokeEdges = superGraph.incomingEdgesOf(node.getContextCFG());
        return new Filter<SuperGraphEdge>() {

            @Override
            protected boolean include(SuperGraphEdge e) {
                return (e instanceof SuperInvokeEdge);
            }
        }.<SuperGraphEdge>filter(cgInvokeEdges);
    } else {
        /* standard edges: incoming edges of cfg node */
        return liftCFGEdges(node.getContextCFG(), node.getContextCFG().getCfg().incomingEdgesOf(cfgNode));
    }
}
Also used : ReturnNode(com.jopdesign.common.code.ControlFlowGraph.ReturnNode) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) Filter(com.jopdesign.common.misc.Filter) VirtualNode(com.jopdesign.common.code.ControlFlowGraph.VirtualNode)

Aggregations

CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)1 ReturnNode (com.jopdesign.common.code.ControlFlowGraph.ReturnNode)1 VirtualNode (com.jopdesign.common.code.ControlFlowGraph.VirtualNode)1 Filter (com.jopdesign.common.misc.Filter)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1