Skip to content

Commit

Permalink
issue #58
Browse files Browse the repository at this point in the history
preEvent generation was buggy and didn't work for while-loops
  • Loading branch information
miho committed Aug 7, 2015
1 parent 95505d7 commit a1c719b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import eu.mihosoft.vrl.lang.model.ControlFlow;
import eu.mihosoft.vrl.lang.model.IArgument;
import eu.mihosoft.vrl.lang.model.Invocation;
import eu.mihosoft.vrl.lang.model.ScopeInvocation;
import eu.mihosoft.vrl.lang.model.Type;
import eu.mihosoft.vrl.lang.model.WhileDeclaration;

/**
* Instrumentation utility class for model based instrumentation.
*
*
* @author Michael Hoffer <[email protected]>
*/
public class VRLInstrumentationUtil {
Expand All @@ -26,14 +28,25 @@ public class VRLInstrumentationUtil {
* @return the generated pre event invocation
*/
public static Invocation generatePreEvent(ControlFlow cf, Invocation inv) {

IArgument[] args = new IArgument[inv.getArguments().size() + 2];

args[0] = Argument.constArg(Type.STRING, inv.getId());
args[1] = Argument.constArg(Type.STRING, inv.getMethodName());

for (int i = 0; i < inv.getArguments().size(); i++) {
args[i + 2] = inv.getArguments().get(i);
IArgument[] args;
// for while-loops we don't add the arguments to the event invocation
// since they are unknown before we enter the loop body
if (inv instanceof ScopeInvocation
&& ((ScopeInvocation) inv).getScope() instanceof WhileDeclaration) {
args = new IArgument[2];
args[0] = Argument.constArg(Type.STRING, inv.getId());
args[1] = Argument.constArg(Type.STRING, inv.getMethodName());
} else {
// ... for all other invocations we add all arguments since they
// are known at event invocation time
args = new IArgument[inv.getArguments().size() + 2];

args[0] = Argument.constArg(Type.STRING, inv.getId());
args[1] = Argument.constArg(Type.STRING, inv.getMethodName());

for (int i = 0; i < inv.getArguments().size(); i++) {
args[i + 2] = inv.getArguments().get(i);
}
}

return cf.callStaticMethod(
Expand Down Expand Up @@ -103,7 +116,8 @@ public static void __preEvent(String id, String invName, Object... args) {
argsStr[i] = "'" + s + "'";
}

System.out.println("pre-event: " + invName + ", id: " + id + ", args: [ " + String.join(", ", argsStr) + " ]");
System.out.println("pre-event: " + invName + ", id: " + id
+ ", args: [ " + String.join(", ", argsStr) + " ]");
}

/**
Expand All @@ -119,7 +133,8 @@ public static void __preEvent(String id, String invName, Object... args) {
public static void __postEvent(String id, String invName, Object retVal) {
String retValStr = "'" + retVal != null ? retVal.toString() : "null" + "'";

System.out.println("post-event: '" + invName + "', id: '" + id + "', ret: [ '" + retValStr + "' ]");
System.out.println("post-event: '" + invName + "', id: '" + id
+ "', ret: [ '" + retValStr + "' ]");
}

/**
Expand All @@ -133,6 +148,7 @@ public static void __postEvent(String id, String invName, Object retVal) {
@Deprecated()
public static void __postEvent(String id, String invName) {

System.out.println("post-event: '" + invName + "', id: '" + id + "', ret: [ void ]");
System.out.println("post-event: '" + invName + "', id: '" + id
+ "', ret: [ void ]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,7 @@ private void instrumentWhileLoop(

// pre-event call for the while-loop invocation
Invocation preWhileEventInv
= cf.callMethod("", "this", "println", Type.VOID,
Argument.constArg(
Type.STRING,
"pre-m-call: "
+ whileLoopInv.getMethodName()
+ ", id: " + whileLoopInv.getId()));
= VRLInstrumentationUtil.generatePreEvent(cf, whileLoopInv);
resultInvs.add(preWhileEventInv);

// introduce condition variable that is used to simulate the original
Expand Down

0 comments on commit a1c719b

Please sign in to comment.