X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fmodule%2Fcoverage%2FCoverageBuilder.java;h=835db7420432aaf018c80051d25b96d8468e8e76;hp=b3bfcd88902bcaf5f9ce731ee1a2b54f05797b0d;hb=ffdf837;hpb=d1a82fe1414c77b97bec886d6a3ae3c5d926c334 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CoverageBuilder.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CoverageBuilder.java index b3bfcd889..835db7420 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CoverageBuilder.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CoverageBuilder.java @@ -10,7 +10,7 @@ public class CoverageBuilder { THashMap> combined = new THashMap>(); - public void addCoverage(Module module) { + public void addCoverage(Module module, boolean persistOverBranchpointReset) { THashMap branchPointMap = module.getBranchPoints(); if(branchPointMap == null) return; @@ -24,25 +24,43 @@ public class CoverageBuilder { @Override public boolean execute(String name, BranchPoint[] branchPoints) { BranchPoint[] oldBranchPoints = oldBranchPointMap_.get(name); - if(oldBranchPoints == null) - oldBranchPointMap_.put(name, branchPoints); - else + if(oldBranchPoints == null) { + if (persistOverBranchpointReset) { + // Clone the branchPoints array so that if will last over a reset + BranchPoint[] clonedBranchPoints = cloneBranchPoints(branchPoints); + oldBranchPointMap_.put(name, clonedBranchPoints); + } else { + // No need to copy so resetting branchpoints will reset this as well + oldBranchPointMap_.put(name, branchPoints); + } + } else { combineCounters(oldBranchPoints, branchPoints); + } return true; } }); } + private static BranchPoint[] cloneBranchPoints(BranchPoint[] oldBranchPoints) { + BranchPoint[] newBranchPoints = new BranchPoint[oldBranchPoints.length]; + for (int i = 0; i < oldBranchPoints.length; i++) { + BranchPoint bp = oldBranchPoints[i]; + BranchPoint[] children = cloneBranchPoints(bp.getChildren()); + newBranchPoints[i] = new BranchPoint(bp.getLocation(), bp.getCodeSize(), children); + } + return newBranchPoints; + } + private static void combineCounters(BranchPoint[] oldBranchPoints, BranchPoint[] branchPoints) { if(oldBranchPoints.length != branchPoints.length) throw new IllegalArgumentException("Incompatible branch points."); for(int i=0;i