Skip to content

Commit

Permalink
code transform interface slightly changed (related to issue #58)
Browse files Browse the repository at this point in the history
temporary indent argument removed since debugging can now be done with much more accurate event handling api
  • Loading branch information
miho committed Aug 10, 2015
1 parent 734e6e5 commit 5fc21fb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
/**
*
* @author Michael Hoffer <[email protected]>
* @param <T>
*/
@FunctionalInterface
public interface CodeTransform<T extends CodeEntity> {
public T transform(T ce, String indent);
/**
*
* @param ce
* @return
*/
public T transform(T ce);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class InstrumentCode implements CodeTransform<CompilationUnitDeclaration>

@Override
public CompilationUnitDeclaration transform(
CompilationUnitDeclaration cu, String indent) {
CompilationUnitDeclaration cu) {

// TODO 01.08.2015 add clone()
CompilationUnitDeclaration result = cu;
Expand All @@ -53,7 +53,7 @@ public CompilationUnitDeclaration transform(
for (ClassDeclaration cd : result.getDeclaredClasses()) {
List<MethodDeclaration> methods = new ArrayList<>();
for (MethodDeclaration md : cd.getDeclaredMethods()) {
methods.add((MethodDeclaration) im.transform(md, indent));
methods.add((MethodDeclaration) im.transform(md));
}
cd.getDeclaredMethods().clear();
cd.getDeclaredMethods().addAll(methods);
Expand Down Expand Up @@ -277,15 +277,15 @@ private Optional<WLLookahead> lookupNextWhileLoop(ControlFlow cf,
}

@Override
public ControlFlowScope transform(ControlFlowScope ce, String indent) {
public ControlFlowScope transform(ControlFlowScope ce) {
// TODO 01.08.2015 add clone()
ControlFlowScope result = ce;

// instrument all incovations of the specified scope
List<Invocation> invocations
= new ArrayList<>(ce.getControlFlow().getInvocations());
ControlFlow cf = result.getControlFlow();
addInstrumentation(cf, invocations, indent);
addInstrumentation(cf, invocations);

return result;
}
Expand All @@ -297,10 +297,9 @@ public ControlFlowScope transform(ControlFlowScope ce, String indent) {
*
* @param cf controlflow
* @param invocations incovations to instrument
* @param indent TODO remove me!!!
*/
private void addInstrumentation(
ControlFlow cf, List<Invocation> invocations, String indent) {
ControlFlow cf, List<Invocation> invocations) {

// instrumented invocations: original invocations with additional
// pre-/post event invocations
Expand Down Expand Up @@ -341,14 +340,14 @@ private void addInstrumentation(

instrumentWhileLoop(cf, wLLookAhead.getCondInvocations(),
wLLookAhead.getWhileInv(),
instrumentedInvocations, indent);
instrumentedInvocations);

// move forward to next invocation after the loop
i += wLLookAhead.getCondInvocations().size();

} else {
instrumentNonLoopInvocation(cf, i, invocations,
instrumentedInvocations, indent);
instrumentedInvocations);
}
} // end for i

Expand All @@ -365,11 +364,9 @@ private void addInstrumentation(
* @param i invocation index
* @param invocations list of all invocations
* @param resultInvs list of instrumented invocations
* @param indent TODO remove me!!
*/
private void instrumentNonLoopInvocation(ControlFlow cf, int i,
List<Invocation> invocations, List<Invocation> resultInvs,
String indent) {
List<Invocation> invocations, List<Invocation> resultInvs) {
Invocation inv = invocations.get(i);

Scope result = cf.getParent();
Expand Down Expand Up @@ -440,7 +437,7 @@ private void instrumentNonLoopInvocation(ControlFlow cf, int i,

if (inv instanceof ScopeInvocation) {
ScopeInvocation si = (ScopeInvocation) inv;
transform((ControlFlowScope) si.getScope(), indent + "--|");
transform((ControlFlowScope) si.getScope());
}
}

Expand Down Expand Up @@ -479,14 +476,12 @@ private Optional<Invocation> isInvArg(Invocation inv, ControlFlow cf) {
* @param cf controlfow
* @param condInvs condition invocations
* @param whileLoopInv while-loop invocation to instrument
* @param resultInvs instrumented invocations
* @param indent TODO remove me!!!
*/
private void instrumentWhileLoop(
ControlFlow cf,
List<Invocation> condInvs,
ScopeInvocation whileLoopInv,
List<Invocation> resultInvs, String indent) {
List<Invocation> resultInvs) {

// pre-event call for the while-loop invocation
Invocation preWhileEventInv
Expand Down Expand Up @@ -521,7 +516,7 @@ private void instrumentWhileLoop(
// body and instrument them. the while-loop body controlflow will be
// cleared afterwards
whileCf.getInvocations().addAll(condInvs);
addInstrumentation(whileCf, condInvs, indent + "while-cond--|");
addInstrumentation(whileCf, condInvs);
List<Invocation> instrumentedCondInvs
= new ArrayList<>(whileCf.getInvocations());
whileCf.getInvocations().clear();
Expand Down Expand Up @@ -551,7 +546,7 @@ private void instrumentWhileLoop(
// of the while-loop body
whileCf.getInvocations().clear();
whileCf.getInvocations().addAll(whileInvocations);
transform(whileScope, indent + "while--|");
transform(whileScope);
List<Invocation> instrumentedWhileInvocations
= new ArrayList<>(whileCf.getInvocations());
whileCf.getInvocations().clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void instrumentationTest() {

InstrumentCode instrumentCode = new InstrumentCode();

CompilationUnitDeclaration newCu = instrumentCode.transform(cu, "--|");
CompilationUnitDeclaration newCu = instrumentCode.transform(cu);

String instrumentedCode = Scope2Code.getCode(newCu);

Expand Down

0 comments on commit 5fc21fb

Please sign in to comment.