Example #1
0
 private static CtStatement appendMonitorCallbacks(
     Factory factory, LoopMonitor monitor, While loop, CtWhile astLoop) {
   String counterName = counterName(monitor);
   if (!loop.isUnbreakable()) {
     insertAfterUnderSameParent(
         newStatementFromSnippet(factory, monitor.invocationOnMonitoringEnd(counterName)),
         astLoop);
   }
   appendMonitoredReturnExit(factory, monitor, loop.returnStatements());
   appendMonitoredBreakExit(factory, monitor, loop.breakStatements());
   return newStatementFromSnippet(factory, monitor.invocationOnLoopError(counterName));
 }
Example #2
0
 private static void appendMonitoredBreakExit(
     Factory factory, LoopMonitor monitor, Collection<CtBreak> breaks) {
   String counterName = counterName(monitor);
   for (CtBreak breakStatement : breaks) {
     CtStatement invocationOnLoopBreak =
         newStatementFromSnippet(factory, monitor.invocationOnLoopBreak(counterName));
     insertBeforeUnderSameParent(invocationOnLoopBreak, breakStatement);
   }
 }
Example #3
0
 private static void appendMonitoredReturnExit(
     Factory factory, LoopMonitor monitor, Collection<CtReturn<?>> returns) {
   String counterName = counterName(monitor);
   for (CtReturn<?> returnStatement : returns) {
     CtStatement invocationOnLoopReturn =
         newStatementFromSnippet(factory, monitor.invocationOnLoopReturn(counterName));
     insertBeforeUnderSameParent(invocationOnLoopReturn, returnStatement);
   }
 }
Example #4
0
 private static void declareConditionEvaluation(
     Factory factory, LoopMonitor monitor, While loop, CtIf newIf) {
   String conditionInvocation =
       monitor.invocationOnLoopConditionEvaluation(
           originalConditionName(monitor), counterName(monitor));
   CtLocalVariable<Boolean> localVariable =
       newLocalVariableDeclaration(
           factory, boolean.class, conditionName(monitor), conditionInvocation);
   insertBeforeUnderSameParent(localVariable, newIf);
 }
Example #5
0
 public static void instrument(LoopMonitor monitor, RuntimeValues<?> runtimeValues) {
   While loop = monitor.loop();
   CtWhile astLoop = loop.astLoop();
   Factory factory = astLoop.getFactory();
   CollectableValueFinder finder = CollectableValueFinder.valueFinderFromWhile(astLoop);
   CtStatement catchCallback = appendMonitorCallbacks(factory, monitor, loop, astLoop);
   CtIf newIf = loopBodyWrapper(factory, monitor, loop, astLoop, catchCallback);
   declareOriginalConditionEvaluation(factory, monitor, loop, newIf);
   declareConditionEvaluation(factory, monitor, loop, newIf);
   declareEntrancesCounter(factory, monitor, astLoop);
   traceReachableValues(monitor, loop, newIf, finder, runtimeValues);
 }
Example #6
0
 private static String originalConditionName(LoopMonitor monitor) {
   return "loopOriginalCondition_" + monitor.instanceID();
 }
Example #7
0
 private static String conditionName(LoopMonitor monitor) {
   return "loopConditionEvaluation_" + monitor.instanceID();
 }
Example #8
0
 private static String catchName(LoopMonitor monitor) {
   return "loopMonitorCatch_" + monitor.instanceID();
 }
Example #9
0
 private static String counterName(LoopMonitor monitor) {
   return "loopEntrancesCounter_" + monitor.instanceID();
 }