예제 #1
0
        public void PointsTo(SimplePTGNode source, IFieldReference field, SimplePTGNode 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);
        }
예제 #2
0
        public bool Reachable(IVariable v1, SimplePTGNode n)
        {
            var ptg    = this;
            var result = false;
            ISet <SimplePTGNode>  visitedNodes = new HashSet <SimplePTGNode>();
            Queue <SimplePTGNode> workList     = new Queue <SimplePTGNode>();
            var nodes = ptg.GetTargets(v1, false);

            if (nodes.Contains(n) && !n.Equals(SimplePointsToGraph.NullNode))
            {
                return(true);
            }

            foreach (var SimplePTGNode in nodes)
            {
                workList.Enqueue(SimplePTGNode);
            }
            while (workList.Any())
            {
                var simplePTGNode = workList.Dequeue();
                visitedNodes.Add(simplePTGNode);
                if (simplePTGNode.Equals(SimplePointsToGraph.NullNode))
                {
                    continue;
                }
                if (simplePTGNode.Equals(n))
                {
                    return(true);
                }
                foreach (var adjacents in ptg.GetTargets(simplePTGNode).Values)
                {
                    foreach (var adjacent in adjacents)
                    {
                        if (!visitedNodes.Contains(adjacent))
                        {
                            workList.Enqueue(adjacent);
                        }
                    }
                }
            }
            return(result);
        }