Skip to content

Commit 18ced24

Browse files
committed
Java: Generalize data-flow library in preparation for C# adoption
1 parent 75ab311 commit 18ced24

File tree

10 files changed

+974
-892
lines changed

10 files changed

+974
-892
lines changed

java/ql/src/semmle/code/java/dataflow/internal/DataFlowDispatch.qll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
private import java
2+
private import DataFlowPrivate
23
import semmle.code.java.dispatch.VirtualDispatch
34

5+
/**
6+
* A return position. A return position describes how a value can return
7+
* from a given callable. For Java, this is simply a method return.
8+
*/
9+
class ReturnPosition extends Method {
10+
ReturnPosition() { exists(ReturnNode ret | ret.getEnclosingCallable() = this) }
11+
12+
/** Gets the callable that a value can be returned from. */
13+
Method getCallable() { result = this }
14+
15+
/** Gets a return node that can return a value at this position. */
16+
ReturnNode getAReturnNode() { result.getEnclosingCallable() = this }
17+
}
18+
419
cached
520
private module DispatchImpl {
621
/**
@@ -186,5 +201,17 @@ private module DispatchImpl {
186201
result = viableImplInCallContext(ma, ctx) and
187202
reducedViableImplInReturn(result, ma)
188203
}
204+
205+
/**
206+
* Gets a node that can read the value returned at position `pos` for the
207+
* call `call`.
208+
*/
209+
cached
210+
OutNode getAnOutputAtCall(DataFlowCall call, ReturnPosition pos) {
211+
exists(Method m | pos.getCallable() = m |
212+
m = viableCallable(call) and
213+
result = call.getNode()
214+
)
215+
}
189216
}
190217
import DispatchImpl

0 commit comments

Comments
 (0)