Skip to content

Commit 0a4ec2c

Browse files
committed
Python: Move some non-points-to methods out of points-to
These methods were in `pointsto.Base` but did not actually interact with the points-to machinery directly, so they were easy to move out.
1 parent f0465f4 commit 0a4ec2c

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

python/ql/lib/semmle/python/essa/Definitions.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ class ModuleVariable extends SsaSourceVariable instanceof GlobalVariable {
276276
override CallNode redefinedAtCallSite() { none() }
277277
}
278278

279+
/** Holds if `f` is an import of the form `from .[...] import ...` and the enclosing scope is an __init__ module */
280+
private predicate import_from_dot_in_init(ImportExprNode f) {
281+
f.getScope() = any(Module m).getInitModule() and
282+
(
283+
f.getNode().getLevel() = 1 and
284+
not exists(f.getNode().getName())
285+
or
286+
f.getNode().getImportedModuleName() = f.getEnclosingModule().getPackage().getName()
287+
)
288+
}
289+
279290
class NonEscapingGlobalVariable extends ModuleVariable {
280291
NonEscapingGlobalVariable() {
281292
this instanceof GlobalVariable and

python/ql/lib/semmle/python/essa/SsaDefinitions.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import python
77
private import semmle.python.internal.CachedStages
88
private import LegacyPointsTo
99

10+
/** Hold if `expr` is a test (a branch) and `use` is within that test */
11+
predicate test_contains(ControlFlowNode expr, ControlFlowNode use) {
12+
expr.getNode() instanceof Expr and
13+
expr.isBranch() and
14+
expr.getAChild*() = use
15+
}
16+
1017
cached
1118
module SsaSource {
1219
/** Holds if `v` is used as the receiver in a method call. */

python/ql/lib/semmle/python/pointsto/Base.qll

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,6 @@ private predicate class_defines_name(Class cls, string name) {
4444
exists(SsaVariable var | name = var.getId() and var.getAUse() = cls.getANormalExit())
4545
}
4646

47-
/** Hold if `expr` is a test (a branch) and `use` is within that test */
48-
predicate test_contains(ControlFlowNode expr, ControlFlowNode use) {
49-
expr.getNode() instanceof Expr and
50-
expr.isBranch() and
51-
expr.getAChild*() = use
52-
}
53-
54-
/** Holds if `f` is an import of the form `from .[...] import ...` and the enclosing scope is an __init__ module */
55-
predicate import_from_dot_in_init(ImportExprNode f) {
56-
f.getScope() = any(Module m).getInitModule() and
57-
(
58-
f.getNode().getLevel() = 1 and
59-
not exists(f.getNode().getName())
60-
or
61-
f.getNode().getImportedModuleName() = f.getEnclosingModule().getPackage().getName()
62-
)
63-
}
64-
6547
/** Gets the pseudo-object representing the value referred to by an undefined variable */
6648
Object undefinedVariable() { py_special_objects(result, "_semmle_undefined_value") }
6749

0 commit comments

Comments
 (0)