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)); }
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); } }
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); } }
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); }
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); }
private static String originalConditionName(LoopMonitor monitor) { return "loopOriginalCondition_" + monitor.instanceID(); }
private static String conditionName(LoopMonitor monitor) { return "loopConditionEvaluation_" + monitor.instanceID(); }
private static String catchName(LoopMonitor monitor) { return "loopMonitorCatch_" + monitor.instanceID(); }
private static String counterName(LoopMonitor monitor) { return "loopEntrancesCounter_" + monitor.instanceID(); }