Skip to content

Commit 57970e8

Browse files
committed
fixing post-event bug related to issue #58
1 parent 4a4e98e commit 57970e8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

VRL/VRL-Lang/src/main/java/eu/mihosoft/vrl/lang/model/transform/InstrumentCode.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import eu.mihosoft.vrl.lang.model.VisualCodeBuilder_Impl;
3030
import eu.mihosoft.vrl.lang.model.WhileDeclaration;
3131
import java.util.ArrayList;
32+
import java.util.Collections;
3233
import java.util.List;
3334
import java.util.Objects;
3435
import java.util.Optional;
@@ -418,10 +419,6 @@ private void instrumentNonLoopInvocation(ControlFlow cf, int i,
418419
// variable
419420
if (invocationTarget.isPresent()) {
420421

421-
if (invocationTarget.get().getMethodName().contains("return")) {
422-
System.out.println("");
423-
}
424-
425422
// search argument indices
426423
int[] argumentsToReplace = invocationTarget.get().
427424
getArguments().stream().
@@ -443,7 +440,6 @@ private void instrumentNonLoopInvocation(ControlFlow cf, int i,
443440
// on the previously defined tmp variable that stores the return
444441
// value of the current invocation
445442
nextI.setObjectProvider(ObjectProvider.fromVariable(varName));
446-
System.out.println("VARNAME: " + varName);
447443
}
448444

449445
retValArg = Argument.varArg(result.getVariable(varName));
@@ -457,6 +453,18 @@ private void instrumentNonLoopInvocation(ControlFlow cf, int i,
457453
resultInvs.add(VRLInstrumentationUtil.generatePostEvent(
458454
cf, inv, retValArg));
459455
}
456+
457+
// if the current invocation is a return,break or continue statement,
458+
// we need to swap the statement invocation and
459+
// the post event invocation since after the return statement no event
460+
// can be generated.
461+
if(inv instanceof ReturnStatementInvocation
462+
|| inv instanceof ContinueInvocation
463+
|| inv instanceof BreakInvocation) {
464+
Collections.swap(resultInvs,
465+
resultInvs.indexOf(inv),
466+
resultInvs.indexOf(inv)+1);
467+
}
460468

461469
if (inv instanceof ScopeInvocation) {
462470
ScopeInvocation si = (ScopeInvocation) inv;

0 commit comments

Comments
 (0)