]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CoverageBuilder.java
Sync git svn branch with SVN repository r33249.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / module / coverage / CoverageBuilder.java
index b3bfcd88902bcaf5f9ce731ee1a2b54f05797b0d..835db7420432aaf018c80051d25b96d8468e8e76 100644 (file)
@@ -10,7 +10,7 @@ public class CoverageBuilder {
     THashMap<String, THashMap<String, BranchPoint[]>> combined =\r
             new THashMap<String, THashMap<String, BranchPoint[]>>();\r
     \r
-    public void addCoverage(Module module) {\r
+    public void addCoverage(Module module, boolean persistOverBranchpointReset) {\r
         THashMap<String, BranchPoint[]> branchPointMap = module.getBranchPoints();\r
         if(branchPointMap == null)\r
             return;\r
@@ -24,25 +24,43 @@ public class CoverageBuilder {
             @Override\r
             public boolean execute(String name, BranchPoint[] branchPoints) {\r
                 BranchPoint[] oldBranchPoints = oldBranchPointMap_.get(name);\r
-                if(oldBranchPoints == null)\r
-                    oldBranchPointMap_.put(name, branchPoints);\r
-                else\r
+                if(oldBranchPoints == null) {\r
+                    if (persistOverBranchpointReset) {\r
+                        // Clone the branchPoints array so that if will last over a reset\r
+                        BranchPoint[] clonedBranchPoints = cloneBranchPoints(branchPoints);\r
+                        oldBranchPointMap_.put(name, clonedBranchPoints);\r
+                    } else {\r
+                        // No need to copy so resetting branchpoints will reset this as well\r
+                        oldBranchPointMap_.put(name, branchPoints);\r
+                    }\r
+                } else {\r
                     combineCounters(oldBranchPoints, branchPoints);\r
+                }\r
                 return true;\r
             }\r
         });\r
     }\r
     \r
+    private static BranchPoint[] cloneBranchPoints(BranchPoint[] oldBranchPoints) {\r
+        BranchPoint[] newBranchPoints = new BranchPoint[oldBranchPoints.length];\r
+        for (int i = 0; i < oldBranchPoints.length; i++) {\r
+            BranchPoint bp = oldBranchPoints[i];\r
+            BranchPoint[] children = cloneBranchPoints(bp.getChildren());\r
+            newBranchPoints[i] = new BranchPoint(bp.getLocation(), bp.getCodeSize(), children);\r
+        }\r
+        return newBranchPoints;\r
+    }\r
+    \r
     private static void combineCounters(BranchPoint[] oldBranchPoints, BranchPoint[] branchPoints) {\r
         if(oldBranchPoints.length != branchPoints.length)\r
             throw new IllegalArgumentException("Incompatible branch points.");\r
         for(int i=0;i<branchPoints.length;++i) {\r
             BranchPoint oldBP = oldBranchPoints[i];\r
             BranchPoint newBP = branchPoints[i];\r
-            if(oldBP.location != newBP.location)\r
+            if(oldBP.getLocation() != newBP.getLocation())\r
                 throw new IllegalArgumentException("Incompatible branch points.");\r
-            oldBP.visitCounter += newBP.visitCounter;\r
-            combineCounters(oldBP.children, newBP.children);\r
+            oldBP.incrementVisitCounter(newBP.getVisitCounter());\r
+            combineCounters(oldBP.getChildren(), newBP.getChildren());\r
         }\r
     }\r
     \r