public void PointsTo(IVariable variable, SimplePTGNode target) { this.Add(target); this.roots.Add(variable, target); target.Variables.Add(variable); }
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); } }
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); }
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)); }
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); }
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); }
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); }
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); }
public bool Contains(SimplePTGNode node) { return(nodes.Contains(node)); }
public void Add(SimplePTGNode node) { nodes.Add(node); }
public virtual SimplePTGNode Clone() { var clone = new SimplePTGNode(this.Id, this.Type, this.Kind); return(clone); }
public NodeField(SimplePTGNode source, IFieldReference field) { this.Node = source; this.Field = field; }