Java Code Examples for com.ibm.wala.util.graph.Graph#addNode()
The following examples show how to use
com.ibm.wala.util.graph.Graph#addNode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SootCallgraphConstructor.java From steady with Apache License 2.0 | 5 votes |
/** * Normalizing a soot callgraph to a general graph represented by ConstructId * * @return a {@link com.ibm.wala.util.graph.Graph} object. */ public Graph<com.sap.psr.vulas.shared.json.model.ConstructId> getCallgraph() { final Graph<com.sap.psr.vulas.shared.json.model.ConstructId> graph = SlowSparseNumberedGraph.make(); if (this.callgraph != null) { int edges_no = 0; com.sap.psr.vulas.shared.json.model.ConstructId src_cid = null, tgt_cid = null; MethodOrMethodContext src_node = null; Iterator<Edge> edges = null; final Iterator<MethodOrMethodContext> src_nodes = callgraph.sourceMethods(); while (src_nodes.hasNext()) { src_node = src_nodes.next(); src_cid = getCid(src_node.method()); graph.addNode(src_cid); //add edges edges = this.callgraph.edgesOutOf(src_node); while (edges.hasNext()) { tgt_cid = getCid(edges.next().tgt()); graph.addNode(tgt_cid); if (!graph.hasEdge(src_cid, tgt_cid)) { graph.addEdge(src_cid, tgt_cid); edges_no++; } } } SootCallgraphConstructor.log.info("Normalized call graph has [" + graph.getNumberOfNodes() + " nodes] (with distinct ConstructId) and [" + edges_no + "] edges"); } // No callgraph exists else { throw new IllegalStateException("There exists no call graph"); } return graph; }
Example 2
Source File: WalaCallgraphConstructor.java From steady with Apache License 2.0 | 5 votes |
/** * Normalizing a wala callgraph to a general graph represented by ConstructId * * @return a {@link com.ibm.wala.util.graph.Graph} object. */ public Graph<com.sap.psr.vulas.shared.json.model.ConstructId> getCallgraph() { Graph<com.sap.psr.vulas.shared.json.model.ConstructId> graph = SlowSparseNumberedGraph.make(); if (this.callgraph != null) { int edges_no = 0; Iterator<CGNode> nodes = this.callgraph.iterator(); CGNode srcnode = null, tgtnode = null; com.sap.psr.vulas.shared.json.model.ConstructId src_cid = null, tgt_cid = null; Iterator<CGNode> succNodes = null; while (nodes.hasNext()) { srcnode = nodes.next(); src_cid = getCid(srcnode.getMethod()); graph.addNode(src_cid); //add edges succNodes = this.callgraph.getSuccNodes(srcnode); while (succNodes.hasNext()) { tgtnode = succNodes.next(); tgt_cid = getCid(tgtnode.getMethod()); graph.addNode(tgt_cid); if (!graph.hasEdge(src_cid, tgt_cid)) { graph.addEdge(src_cid, tgt_cid); edges_no++; } } } WalaCallgraphConstructor.log.info("Normalized call graph has [" + graph.getNumberOfNodes() + " nodes] (with distinct ConstructId) and [" + edges_no + " edges]"); } // No callgrpah exists else { throw new IllegalStateException("There exists no call graph"); } return graph; }
Example 3
Source File: Planner.java From quetzal with Eclipse Public License 2.0 | 4 votes |
public PlanNode join(JoinTypes type, Query query, Graph<PlanNode> plan, PlanNode lhs, PlanNode rhs, Set<Variable> liveVars) { plan.addNode(rhs); if (lhs == null) { return rhs; } else if (type.type() == PlanNodeType.AND && !BINARY_PLANS && lhs.getType() == PlanNodeType.AND) { plan.addEdge(lhs, rhs); return lhs; } else { Set<Variable> operator = HashSetFactory.make(lhs.getAvailableVariables()); Set<Variable> x = HashSetFactory.make(rhs.getRequiredVariables()); x.addAll(rhs.getProducedVariables()); operator.retainAll(x); PlanNode and = planFactory.createSTPlanNode( type.type(), Collections.<Variable> emptySet(), query.getMainPattern()); Set<Variable> availableVariables; if (lhs.getAvailableVariables() == null) { availableVariables = HashSetFactory.make(); } else { availableVariables = HashSetFactory.make(lhs.getAvailableVariables()); } if (rhs.getProducedVariables() != null && !type.equals(JoinTypes.NOT_EXISTS) && !type.equals(JoinTypes.EXISTS)) { availableVariables.addAll(rhs.getProducedVariables()); } Set<Variable> allVars = HashSetFactory.make(liveVars); availableVariables.retainAll(allVars); and.setProducedVariables(HashSetFactory.make(availableVariables)); and.setAvailableVariables(HashSetFactory.make(availableVariables)); //assert !operator.isEmpty(); and.setOperatorsVariables(operator); plan.addNode(and); plan.addEdge(and, lhs); plan.addEdge(and, rhs); and.cost = add(lhs.cost, rhs.cost); if (lhs.getFilters() != null || rhs.getFilters() != null) { List<Expression> filters = lhs.getFilters()!=null? new LinkedList<Expression>(lhs.getFilters()): new LinkedList<Expression>(); if (type.type() == PlanNodeType.AND && rhs.getFilters() != null) { filters.addAll(rhs.getFilters()); } and.setFilters(filters); } return and; } }