예제 #1
0
        /// <summary>
        /// Checks whether a definition and use are in different methods
        /// </summary>
        /// <param name="dcse"></param>
        /// <returns></returns>
        private bool IsFeasibleDUCoverEntry(DUCoverStore dcs, FieldDefUseStore fdef, FieldDefUseStore fuse)
        {
            //if (fdef.Method.FullName.Contains("AddVertex") && fuse.Method.FullName.Contains("AddVertex") && fdef.Field.FullName.Contains("m_VertexOutEdges")
            //    && fdef.Offset == 13 && fuse.Offset == 2)
            //{
            //    int i = 0;
            //}

            //check whether the def and use are in the same method
            if (fdef.Method.Equals(fuse.Method))
            {
                var otherFDefOffsets    = this.GetOtherDefOffsetsInMethod(fdef.Method, fdef);
                InstructionGraph    ig  = dcs.GetInstructionGraph(fdef.Method);
                DepthFirstTraversal dft = new DepthFirstTraversal(ig);
                var source = ig.GetVertex(fdef.Offset);
                var target = ig.GetVertex(fuse.Offset);
                return(dft.HasDefClearPathBetweenNodes(source, target, otherFDefOffsets));
            }
            else
            {
                var otherFDefOffsets = this.GetOtherDefOffsetsInMethod(fdef.Method, fdef);
                if (otherFDefOffsets.Count > 0)
                {
                    if (this.HasRedefinition(dcs, fdef, otherFDefOffsets))
                    {
                        return(false);
                    }
                }

                otherFDefOffsets = this.GetOtherDefOffsetsInMethod(fuse.Method, fdef);
                if (otherFDefOffsets.Count > 0)
                {
                    if (this.HasDefinitionFromRootToUseNode(dcs, fuse, otherFDefOffsets))
                    {
                        return(false);
                    }
                }

                return(true);
            }
        }