Пример #1
0
        private void CreateInitialGraph()
        {
            var ptg       = new PointsToGraph();
            var variables = cfg.GetVariables();

            foreach (var variable in variables)
            {
                if (variable.Type.IsValueType)
                {
                    continue;
                }

                if (variable.IsParameter)
                {
                    var isThisParameter = variable.Name == "this";
                    var kind            = isThisParameter ? PTGNodeKind.Object : PTGNodeKind.Unknown;
                    var node            = new PTGNode(nextPTGNodeId++, variable.Type, 0, kind);

                    ptg.Add(node);
                    ptg.PointsTo(variable, node);
                }
                else
                {
                    ptg.Add(variable);
                }
            }

            this.initialGraph = ptg;
        }
Пример #2
0
        public PointsToGraph()
        {
            this.Null      = new PTGNode(0, PTGNodeKind.Null);
            this.variables = new MapSet <IVariable, PTGNode>();
            this.nodes     = new Dictionary <int, PTGNode>();

            this.Add(this.Null);
        }
Пример #3
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);
                    }
                }
            }
        }
Пример #4
0
        public bool SameEdges(PTGNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            return(this.Variables.SetEquals(node.Variables) &&
                   this.Sources.MapEquals(node.Sources) &&
                   this.Targets.MapEquals(node.Targets));
        }
Пример #5
0
        public void PointsTo(IVariable variable, PTGNode target)
        {
#if DEBUG
            if (!this.Contains(target))
            {
                throw new ArgumentException("Target node does not belong to this Points-to graph.", "target");
            }
#endif

            target.Variables.Add(variable);
            this.variables.Add(variable, target);
        }
Пример #6
0
        public void PointsTo(PTGNode source, IFieldReference field, PTGNode target)
        {
#if DEBUG
            if (!this.Contains(source))
            {
                throw new ArgumentException("Source node does not belong to this Points-to graph.", "source");
            }

            if (!this.Contains(target))
            {
                throw new ArgumentException("Target node does not belong to this Points-to graph.", "target");
            }
#endif

            source.Targets.Add(field, target);
            target.Sources.Add(field, source);
        }
Пример #7
0
        private PTGNode GetNode(PointsToGraph ptg, uint offset, ITypeReference type, PTGNodeKind kind = PTGNodeKind.Object)
        {
            PTGNode node;

            if (nodeIdAtOffset.ContainsKey(offset))
            {
                var nodeId = nodeIdAtOffset[offset];
                node = ptg.GetNode(nodeId);
            }
            else
            {
                var nodeId = nextPTGNodeId++;
                node = new PTGNode(nodeId, type, offset, kind);

                ptg.Add(node);
                nodeIdAtOffset.Add(offset, nodeId);
            }

            return(node);
        }
Пример #8
0
 public void Add(PTGNode node)
 {
     nodes.Add(node.Id, node);
 }
Пример #9
0
 public bool Contains(PTGNode node)
 {
     return(this.ContainsNode(node.Id));
 }