Browse Source

CodeCoverage: refactoring

Improved finding of method-body-last-unique-SequencePoint
getBodyStartSP/getBodyFinalSP called only once
and btw licence change
pull/67/head
Dragan 12 years ago
parent
commit
cb4edbc1a8
  1. 2
      src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageBranchPoint.cs
  2. 62
      src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs
  3. 2
      src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageStringTextSource.cs

2
src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageBranchPoint.cs

@ -1,5 +1,5 @@
// Copyright (c) https://github.com/ddur // Copyright (c) https://github.com/ddur
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the MIT license
using System; using System;

62
src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs

@ -39,6 +39,8 @@ namespace ICSharpCode.CodeCoverage
public bool IsConstructor { get; private set; } public bool IsConstructor { get; private set; }
public bool IsStatic { get; private set; } public bool IsStatic { get; private set; }
public List<CodeCoverageSequencePoint> SequencePoints { get; private set; } public List<CodeCoverageSequencePoint> SequencePoints { get; private set; }
public CodeCoverageSequencePoint BodyStartSP { get; private set; }
public CodeCoverageSequencePoint BodyFinalSP { get; private set; }
public List<CodeCoverageBranchPoint> BranchPoints { get; private set; } public List<CodeCoverageBranchPoint> BranchPoints { get; private set; }
public bool IsGetter { get; private set; } public bool IsGetter { get; private set; }
@ -129,19 +131,19 @@ namespace ICSharpCode.CodeCoverage
// is inserted into this method sequence points // is inserted into this method sequence points
// //
// To remove alien sequence points, all points // To remove alien sequence points, all points
// before and after method brackets {} are removed // before method signature and after end-brackets xxx{} are removed
CodeCoverageSequencePoint startSP = getBodyStartSP(sps); this.BodyStartSP = getBodyStartSP(sps);
if (Object.ReferenceEquals(null, startSP)) { return sps; } if (this.BodyStartSP == null) { return sps; }
CodeCoverageSequencePoint finalSP = getBodyFinalSP(sps);
if (Object.ReferenceEquals(null, finalSP)) { return sps; } this.BodyFinalSP = getBodyFinalSP(sps);
if (this.BodyFinalSP == null) { return sps; }
bool foundFinalSP = false;
List<CodeCoverageSequencePoint> selected = new List<CodeCoverageSequencePoint>(); List<CodeCoverageSequencePoint> selected = new List<CodeCoverageSequencePoint>();
foreach (var point in sps) { foreach (var point in sps) {
if ( if (
(point.Line > startSP.Line || (point.Line == startSP.Line && point.Column >= startSP.Column)) && (point.Line > BodyStartSP.Line || (point.Line == BodyStartSP.Line && point.Column >= BodyStartSP.Column)) &&
(point.Line < finalSP.Line || (point.Line == finalSP.Line && point.Column < finalSP.Column)) (point.Line < BodyFinalSP.Line || (point.Line == BodyFinalSP.Line && point.Column < BodyFinalSP.Column))
) { ) {
selected.Add (point); selected.Add (point);
} }
@ -152,16 +154,13 @@ namespace ICSharpCode.CodeCoverage
// Note: IL.Offset of second duplicate finalSP will // Note: IL.Offset of second duplicate finalSP will
// extend branch coverage outside method-end "}", // extend branch coverage outside method-end "}",
// and that can lead to wrong branch coverage report! // and that can lead to wrong branch coverage report!
if (!foundFinalSP) { if (object.ReferenceEquals (point, this.BodyFinalSP)) {
if (point.Line == finalSP.Line && point.Column == finalSP.Column) { selected.Add (point);
selected.Add (point);
foundFinalSP = true;
}
} }
} }
selected.OrderBy(item => item.Line).OrderBy(item => item.Column);
sps = selected; sps = selected;
sps.OrderBy(item => item.Line).OrderBy(item => item.Column);
} }
return sps; return sps;
@ -195,7 +194,7 @@ namespace ICSharpCode.CodeCoverage
return bps; return bps;
} }
// Find method-body start SequencePoint "{" // Find method-body start SequencePoint "xxxx {"
public static CodeCoverageSequencePoint getBodyStartSP(IEnumerable<CodeCoverageSequencePoint> sPoints) { public static CodeCoverageSequencePoint getBodyStartSP(IEnumerable<CodeCoverageSequencePoint> sPoints) {
CodeCoverageSequencePoint startSeqPoint = null; CodeCoverageSequencePoint startSeqPoint = null;
bool startFound = false; bool startFound = false;
@ -214,10 +213,19 @@ namespace ICSharpCode.CodeCoverage
public static CodeCoverageSequencePoint getBodyFinalSP(IEnumerable<CodeCoverageSequencePoint> sps) { public static CodeCoverageSequencePoint getBodyFinalSP(IEnumerable<CodeCoverageSequencePoint> sps) {
CodeCoverageSequencePoint finalSeqPoint = null; CodeCoverageSequencePoint finalSeqPoint = null;
foreach (CodeCoverageSequencePoint sp in Enumerable.Reverse(sps)) { foreach (CodeCoverageSequencePoint sp in Enumerable.Reverse(sps)) {
if ( sp.Content == "}") { if ( sp.Content == "}") {
finalSeqPoint = sp; if (finalSeqPoint == null) {
break; finalSeqPoint = sp;
} }
// check for ccrewrite duplicate
else if (sp.Line == finalSeqPoint.Line &&
sp.Column == finalSeqPoint.Column &&
sp.EndLine == finalSeqPoint.EndLine &&
sp.EndColumn == finalSeqPoint.EndColumn &&
sp.Offset < finalSeqPoint.Offset) {
finalSeqPoint = sp;
}
}
} }
return finalSeqPoint; return finalSeqPoint;
} }
@ -237,24 +245,22 @@ namespace ICSharpCode.CodeCoverage
// This sequence point offset is used to skip CCRewrite(n) BranchPoint's (Requires) // This sequence point offset is used to skip CCRewrite(n) BranchPoint's (Requires)
// and '{' branches at static methods // and '{' branches at static methods
CodeCoverageSequencePoint startSeqPoint = getBodyStartSP(this.SequencePoints); if (this.BodyStartSP == null) { return null; }
if (Object.ReferenceEquals(null, startSeqPoint)) { return null; }
// This sequence point offset is used to skip CCRewrite(n) BranchPoint's (Ensures) // This sequence point offset is used to skip CCRewrite(n) BranchPoint's (Ensures)
CodeCoverageSequencePoint finalSeqPoint = getBodyFinalSP(this.SequencePoints); if (this.BodyFinalSP == null) { return null; }
if (Object.ReferenceEquals(null, finalSeqPoint)) { return null; }
// Connect Sequence & Branches // Connect Sequence & Branches
IEnumerator<CodeCoverageSequencePoint> SPEnumerator = this.SequencePoints.GetEnumerator(); IEnumerator<CodeCoverageSequencePoint> SPEnumerator = this.SequencePoints.GetEnumerator();
CodeCoverageSequencePoint currSeqPoint = startSeqPoint; CodeCoverageSequencePoint currSeqPoint = BodyStartSP;
int nextSeqPointOffset = startSeqPoint.Offset; int nextSeqPointOffset = BodyStartSP.Offset;
foreach (var bp in this.BranchPoints) { foreach (var bp in this.BranchPoints) {
// ignore branches outside of method body // ignore branches outside of method body offset range
if (bp.Offset < startSeqPoint.Offset) if (bp.Offset < BodyStartSP.Offset)
continue; continue;
if (bp.Offset > finalSeqPoint.Offset) if (bp.Offset > BodyFinalSP.Offset)
break; break;
// Sync with SequencePoint // Sync with SequencePoint

2
src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageStringTextSource.cs

@ -1,5 +1,5 @@
// Copyright (c) https://github.com/ddur // Copyright (c) https://github.com/ddur
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under MIT license
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

Loading…
Cancel
Save