public void PointsTo(PTGNode source, IFieldReference field, PTGNode target) { if (source.Equals(SimplePointsToGraph.NullNode)) { return; } this.nodes.Add(target); this.nodes.Add(source); var currentTargets = GetTargets(source, field); if (currentTargets.Count == 1 && currentTargets.Single() == SimplePointsToGraph.NullNode) { this.RemoveTargets(source, field); } this.AddEdge(source, field, target); }
public bool Reachable(IVariable v1, PTGNode n) { var ptg = this; var result = false; ISet <PTGNode> visitedNodes = new HashSet <PTGNode>(); Queue <PTGNode> workList = new Queue <PTGNode>(); var nodes = ptg.GetTargets(v1, false); if (nodes.Contains(n) && !n.Equals(SimplePointsToGraph.NullNode)) { return(true); } foreach (var ptgNode in nodes) { workList.Enqueue(ptgNode); } while (workList.Any()) { var ptgNode = workList.Dequeue(); visitedNodes.Add(ptgNode); if (ptgNode.Equals(SimplePointsToGraph.NullNode)) { continue; } if (ptgNode.Equals(n)) { return(true); } foreach (var adjacents in ptg.GetTargets(ptgNode).Values) { foreach (var adjacent in adjacents) { if (!visitedNodes.Contains(adjacent)) { workList.Enqueue(adjacent); } } } } return(result); }