Skip to content

Commit

Permalink
added forObjectPost
Browse files Browse the repository at this point in the history
  • Loading branch information
Haiyang-Sun committed Sep 17, 2019
1 parent d687a04 commit 4293fa1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/ch.usi.inf.nodeprof/js/analysis/forinof/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
this.forObject = function (iid, isForIn) {
console.log('forObject@', J$.iidToLocation(iid), isForIn, lastExprResult);
}
this.forObjectPost = function (iid, isForIn) {
console.log('forObjectPost@', J$.iidToLocation(iid), isForIn);
}
this.endExpression = function (iid, type, result) {
lastExprResult = result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
forObject@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:6:1:7:2) true { x: 'valueX', y: 'valueY' }
forObjectPost@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:6:1:7:2) true
forObject@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2) false [ 41, 42, 43 ]
forObjectPost@ (src/ch.usi.inf.nodeprof.test/js/minitests/forinof.js:11:1:12:2) false
2 changes: 2 additions & 0 deletions src/ch.usi.inf.nodeprof/js/analysis/trivial/emptyTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
**/
this.forObject = function (iid, isForIn) {
}
this.forObjectPost = function (iid, isForIn) {
}

/**
* This callback is called before a value is returned from a function using the <tt>return</tt> keyword.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class JalangiAnalysis {
put("evalFunctionPost", EnumSet.of(BUILTIN));

put("forObject", EnumSet.of(CF_ROOT));
put("forObjectPost", EnumSet.of(CF_ROOT));

put("_return", EnumSet.of(CF_BRANCH));

Expand Down Expand Up @@ -271,10 +272,10 @@ public void onReady() {
new EvalFunctionFactory(this.jsAnalysis, callbacks.get("evalFunctionPre"), callbacks.get("evalFunctionPost")));
}

if (this.callbacks.containsKey("forObject")) {
if (this.callbacks.containsKey("forObject") || this.callbacks.containsKey("forObjectPost")) {
this.instrument.onCallback(
ProfiledTagEnum.CF_ROOT,
new ForObjectFactory(this.jsAnalysis, callbacks.get("forObject")));
new ForObjectFactory(this.jsAnalysis, callbacks.get("forObject"), callbacks.get("forObjectPost")));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
import ch.usi.inf.nodeprof.handlers.LoopEventHandler;

public class ForObjectFactory extends AbstractFactory {
public ForObjectFactory(Object jalangiAnalysis, DynamicObject pre) {
super("forObject", jalangiAnalysis, pre, null, 2, -1);
public ForObjectFactory(Object jalangiAnalysis, DynamicObject pre, DynamicObject post) {
super("forObject", jalangiAnalysis, pre, post, 2, 2);
}

@Override
public BaseEventHandlerNode create(EventContext context) {
return new LoopEventHandler(context) {
@Child DirectCallNode preCall = createPreCallNode();
@Child DirectCallNode postCall = createPostCallNode();

@Override
public void executePre(VirtualFrame frame,
Expand All @@ -42,6 +43,16 @@ public void executePre(VirtualFrame frame,
directCall(preCall, true, getSourceIID());
}
}

@Override
public void executePost(VirtualFrame frame, Object result, Object[] inputs) {
if (post != null && (isForIn() || isForOf())) {
setPostArguments(0, getSourceIID());
setPostArguments(1, isForIn());
directCall(postCall, true, getSourceIID());
}

}
};
}

Expand Down

0 comments on commit 4293fa1

Please sign in to comment.