Skip to content

Commit a319088

Browse files
committed
python: expose getNodeFromPath in a nicer way
1 parent 36ba3ba commit a319088

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

python/ql/lib/semmle/python/dataflow/new/FlowSummary.qll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ abstract class SummarizedCallable extends LibraryCallable, Impl::Public::Summari
7070

7171
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
7272

73-
// // This gives access to getNodeFromPath, which is not constrained to `CallNode`s
74-
// // as `resolvedSummaryBase` is.
75-
private import semmle.python.frameworks.data.internal.ApiGraphModels as AGM
76-
7773
private class SummarizedCallableFromModel extends SummarizedCallable {
7874
string type;
7975
string path;
@@ -92,7 +88,7 @@ private class SummarizedCallableFromModel extends SummarizedCallable {
9288

9389
override ArgumentNode getACallback() {
9490
exists(API::Node base |
95-
base = AGM::getNodeFromPath(type, path) and
91+
ModelOutput::resolvedSummaryRefBase(type, path, base) and
9692
result = base.getAValueReachableFromSource()
9793
)
9894
}

python/ql/lib/semmle/python/frameworks/data/internal/ApiGraphModels.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ private API::Node getNodeFromSubPath(API::Node base, AccessPath subPath) {
522522
}
523523

524524
/** Gets the node identified by the given `(type, path)` tuple. */
525-
API::Node getNodeFromPath(string type, AccessPath path) {
525+
private API::Node getNodeFromPath(string type, AccessPath path) {
526526
result = getNodeFromPath(type, path, path.getNumToken())
527527
}
528528

@@ -644,6 +644,15 @@ module ModelOutput {
644644
baseNode = getInvocationFromPath(type, path)
645645
}
646646

647+
/**
648+
* Holds if a `baseNode` is an invocation identified by the `type,path` part of a summary row.
649+
*/
650+
cached
651+
predicate resolvedSummaryRefBase(string type, string path, API::Node baseNode) {
652+
summaryModel(type, path, _, _, _) and
653+
baseNode = getNodeFromPath(type, path)
654+
}
655+
647656
/**
648657
* Holds if `node` is seen as an instance of `type` due to a type definition
649658
* contributed by a CSV model.

0 commit comments

Comments
 (0)