Search in sources :

Example 1 with Filter

use of com.jopdesign.common.misc.Filter 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)

Example 2 with Filter

use of com.jopdesign.common.misc.Filter in project jop by jop-devel.

the class SuperGraph method outgoingEdgesOf.

/**
	 * The outgoing edges are generated as follows:
	 * <ul>
	 * <li/>invoke node: superedge invoking the callee
	 * <li/>exit node: superedge returning to the caller
	 * <li/>other: intraprocedural CFG edge
	 * </ul>
	 * @param node
	 * @return
	 */
public Iterable<SuperGraphEdge> outgoingEdgesOf(SuperGraphNode node) {
    CFGNode cfgNode = node.getCFGNode();
    if (cfgNode instanceof InvokeNode) {
        /* invoke node: outgoing SuperInvoke edges */
        final InvokeNode invNode = (InvokeNode) cfgNode;
        Set<SuperEdge> outgoingInvokeEdges = superGraph.outgoingEdgesOf(node.getContextCFG());
        return new Filter<SuperGraphEdge>() {

            @Override
            protected boolean include(SuperGraphEdge e) {
                if (!(e instanceof SuperInvokeEdge))
                    return false;
                SuperInvokeEdge invoke = (SuperInvokeEdge) e;
                return invoke.getInvokeNode().equals(invNode);
            }
        }.<SuperGraphEdge>filter(outgoingInvokeEdges);
    } else if (cfgNode instanceof VirtualNode && ((VirtualNode) cfgNode).getKind() == VirtualNodeKind.EXIT) {
        /* exit node: outgoing SuperReturn edges */
        Set<SuperEdge> outgoingReturnEdges = superGraph.outgoingEdgesOf(node.getContextCFG());
        return new Filter<SuperGraphEdge>() {

            @Override
            protected boolean include(SuperGraphEdge e) {
                return (e instanceof SuperReturnEdge);
            }
        }.<SuperGraphEdge>filter(outgoingReturnEdges);
    } else {
        /* standard edges: outgoing edges of cfg node */
        Set<CFGEdge> outgoingCFGEdges = node.getContextCFG().getCfg().outgoingEdgesOf(cfgNode);
        return liftCFGEdges(node.getContextCFG(), outgoingCFGEdges);
    }
}
Also used : 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) InvokeNode(com.jopdesign.common.code.ControlFlowGraph.InvokeNode)

Aggregations

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