/// <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; } }
/// <summary> /// Checks whether the fdef has a redefinition from the current not to the end of the method /// </summary> /// <param name="fdef"></param> /// <param name="otherDefinedOffsets"></param> /// <returns></returns> private bool HasRedefinition(DUCoverStore dcs, FieldDefUseStore fdef, HashSet<int> otherDefinedOffsets) { DEFUSE_FEASIBILITY_TYPE feasibilityVal; if (this.feasibilityDicCache.TryGetValue(fdef, out feasibilityVal)) { if (feasibilityVal == DEFUSE_FEASIBILITY_TYPE.DEF_FEASIBLE) return false; else return true; } InstructionGraph ig = dcs.GetInstructionGraph(fdef.Method); DepthFirstTraversal dft = new DepthFirstTraversal(ig); InstructionVertex iv = ig.GetVertex(fdef.Offset); var result = dft.HasDefClearPathToEnd(iv, otherDefinedOffsets); if (result) this.feasibilityDicCache[fdef] = DEFUSE_FEASIBILITY_TYPE.DEF_FEASIBLE; else this.feasibilityDicCache[fdef] = DEFUSE_FEASIBILITY_TYPE.DEF_INFEASIBLE; return !result; }