Ejemplo n.º 1
0
        public void PointsTo(IVariable variable, SimplePTGNode target)
        {
            this.Add(target);
            this.roots.Add(variable, target);

            target.Variables.Add(variable);
        }
Ejemplo n.º 2
0
 public void RemoveTargets(SimplePTGNode source, IFieldReference field)
 {
     //var nodeField = new NodeField(source, field);
     //this.edges.Remove(nodeField);
     if (this.edges.ContainsKey(source))
     {
         var nodeFields = this.edges[source].Where(nf => !nf.Field.Name.Value.Equals(field.Name.Value));
         this.edges[source] = new HashSet <NodeField>(nodeFields);
     }
 }
Ejemplo n.º 3
0
        public void AddEdge(SimplePTGNode source, IFieldReference field, SimplePTGNode target)
        {
            //var nodeField = new NodeField(source, field);
            //if(edges.ContainsKey(nodeField))
            //{ }
            //this.edges.Add(nodeField, target);
            var nodeField = new NodeField(target, field);

            this.edges.Add(source, nodeField);
        }
Ejemplo n.º 4
0
        public bool SameEdges(SimplePTGNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return(this.Variables.SetEquals(node.Variables) &&
                   this.Sources.MapEquals(node.Sources) &&
                   this.Targets.MapEquals(node.Targets));
        }
Ejemplo n.º 5
0
        public ISet <SimplePTGNode> GetTargets(SimplePTGNode source, IFieldReference field)
        {
            var result = new HashSet <SimplePTGNode>();

            //var nodeField = new NodeField(source, field);
            //if (this.edges.ContainsKey(nodeField))
            //{
            //    result.UnionWith(this.edges[nodeField]);
            //}
            if (this.edges.ContainsKey(source))
            {
                result.AddRange(this.edges[source].Where(nf => nf.Field.Name.Value.Equals(field.Name.Value)).Select(nf => nf.Node));
            }
            return(result);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public MapSet <IFieldReference, SimplePTGNode> GetTargets(SimplePTGNode source)
        {
            //var result = new MapSet<IFieldReference, SimplePTGNode>();
            //foreach (var edge in this.edges.Where(kv => kv.Key.Source.Equals(SimplePTGNode)))
            //{
            //    result.AddRange(edge.Key.Field, edge.Value);
            //}
            //return result;
            var result = new MapSet <IFieldReference, SimplePTGNode>();

            if (this.edges.ContainsKey(source))
            {
                foreach (var nodeField in this.edges[source])
                {
                    result.Add(nodeField.Field, nodeField.Node);
                }
            }
            return(result);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 public bool Contains(SimplePTGNode node)
 {
     return(nodes.Contains(node));
 }
Ejemplo n.º 10
0
 public void Add(SimplePTGNode node)
 {
     nodes.Add(node);
 }
Ejemplo n.º 11
0
        public virtual SimplePTGNode Clone()
        {
            var clone = new SimplePTGNode(this.Id, this.Type, this.Kind);

            return(clone);
        }
Ejemplo n.º 12
0
 public NodeField(SimplePTGNode source, IFieldReference field)
 {
     this.Node  = source;
     this.Field = field;
 }