Skip to content

Commit

Permalink
Merge pull request #17789 from aschackmull/python/resolvecall-refactor
Browse files Browse the repository at this point in the history
Python: Refactor references to NormalCall.
  • Loading branch information
yoff authored Nov 1, 2024
2 parents 0bb5b4b + 8b57565 commit cec0544
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions python/ql/src/meta/analysis-quality/CallGraphQuality.qll
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@ module TypeTrackingBasedCallGraph {
/** A call that can be resolved by type-tracking. */
class ResolvableCall extends RelevantCall {
ResolvableCall() {
exists(TT::TNormalCall(this, _, _))
TT::resolveCall(this, _, _)
or
TT::resolveClassCall(this, _)
}

/** Gets a resolved target of this call. */
Target getTarget() {
exists(TT::DataFlowCall call, TT::CallType ct, Function targetFunc |
call = TT::TNormalCall(this, targetFunc, ct) and
exists(TT::CallType ct, Function targetFunc |
TT::resolveCall(this, targetFunc, ct) and
not ct instanceof TT::CallTypeClass and
targetFunc = result.(TargetFunction).getFunction()
)
or
// a TT::TNormalCall only exists when the call can be resolved to a function.
// TT::resolveCall only holds when the call can be resolved to a function.
// Since points-to just says the call goes directly to the class itself, and
// type-tracking based wants to resolve this to the constructor, which might not
// exist. So to do a proper comparison, we don't require the call to be resolve to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ predicate typeTrackerCallEdge(CallNode call, Function callable) {
predicate typeTrackerClassCall(CallNode call, Function callable) {
exists(call.getLocation().getFile().getRelativePath()) and
exists(callable.getLocation().getFile().getRelativePath()) and
exists(TT::NormalCall cc |
cc = TT::TNormalCall(call, _, any(TT::TCallType t | t instanceof TT::CallTypeClass)) and
TT::TFunction(callable) = TT::viableCallable(cc)
)
TT::resolveCall(call, callable, any(TT::TCallType t | t instanceof TT::CallTypeClass))
}

module CallGraphTest implements TestSig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ module DataFlowCallTest implements TestSig {
value = prettyExpr(call.getNode().getNode()) and
tag = "call"
or
value = call.(DataFlowDispatch::NormalCall).getCallType().toString() and
tag = "callType"
exists(DataFlowDispatch::CallType callType |
DataFlowDispatch::resolveCall(call.getNode(), _, callType) and
value = callType.toString() and
tag = "callType"
)
or
exists(DataFlowDispatch::ArgumentPosition pos, DataFlow::Node arg |
arg = call.getArgument(pos)
Expand Down

0 comments on commit cec0544

Please sign in to comment.