Example #1
0
        public PointsToGraph Clone()
        {
            var ptg = new PointsToGraph();

            ptg.Union(this);
            return(ptg);
        }
Example #2
0
        public void Union(PointsToGraph ptg)
        {
            // add all new nodes
            foreach (var node in ptg.Nodes)
            {
                if (this.Contains(node))
                {
                    continue;
                }
                var clone = new PTGNode(node.Id, node.Type, node.Offset, node.Kind);

                nodes.Add(clone.Id, clone);
            }

            // add all variables
            foreach (var variable in ptg.Variables)
            {
                this.variables.Add(variable);
            }

            // add all edges
            foreach (var node in ptg.Nodes)
            {
                var clone = nodes[node.Id];

                // add variable <---> node edges
                foreach (var variable in node.Variables)
                {
                    clone.Variables.Add(variable);
                    this.variables.Add(variable, clone);
                }

                // add source -field-> node edges
                foreach (var entry in node.Sources)
                {
                    foreach (var source in entry.Value)
                    {
                        var source_clone = nodes[source.Id];

                        clone.Sources.Add(entry.Key, source_clone);
                    }
                }

                // add node -field-> target edges
                foreach (var entry in node.Targets)
                {
                    foreach (var target in entry.Value)
                    {
                        var target_clone = nodes[target.Id];

                        clone.Targets.Add(entry.Key, target_clone);
                    }
                }
            }
        }