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.
This commit is contained in:
Taus
2025-10-30 16:46:33 +00:00
parent f0465f441f
commit 0a4ec2ca10
3 changed files with 18 additions and 18 deletions

View File

@@ -276,6 +276,17 @@ class ModuleVariable extends SsaSourceVariable instanceof GlobalVariable {
override CallNode redefinedAtCallSite() { none() } override CallNode redefinedAtCallSite() { none() }
} }
/** Holds if `f` is an import of the form `from .[...] import ...` and the enclosing scope is an __init__ module */
private predicate import_from_dot_in_init(ImportExprNode f) {
f.getScope() = any(Module m).getInitModule() and
(
f.getNode().getLevel() = 1 and
not exists(f.getNode().getName())
or
f.getNode().getImportedModuleName() = f.getEnclosingModule().getPackage().getName()
)
}
class NonEscapingGlobalVariable extends ModuleVariable { class NonEscapingGlobalVariable extends ModuleVariable {
NonEscapingGlobalVariable() { NonEscapingGlobalVariable() {
this instanceof GlobalVariable and this instanceof GlobalVariable and

View File

@@ -7,6 +7,13 @@ import python
private import semmle.python.internal.CachedStages private import semmle.python.internal.CachedStages
private import LegacyPointsTo private import LegacyPointsTo
/** Hold if `expr` is a test (a branch) and `use` is within that test */
predicate test_contains(ControlFlowNode expr, ControlFlowNode use) {
expr.getNode() instanceof Expr and
expr.isBranch() and
expr.getAChild*() = use
}
cached cached
module SsaSource { module SsaSource {
/** Holds if `v` is used as the receiver in a method call. */ /** Holds if `v` is used as the receiver in a method call. */

View File

@@ -44,24 +44,6 @@ private predicate class_defines_name(Class cls, string name) {
exists(SsaVariable var | name = var.getId() and var.getAUse() = cls.getANormalExit()) exists(SsaVariable var | name = var.getId() and var.getAUse() = cls.getANormalExit())
} }
/** Hold if `expr` is a test (a branch) and `use` is within that test */
predicate test_contains(ControlFlowNode expr, ControlFlowNode use) {
expr.getNode() instanceof Expr and
expr.isBranch() and
expr.getAChild*() = use
}
/** Holds if `f` is an import of the form `from .[...] import ...` and the enclosing scope is an __init__ module */
predicate import_from_dot_in_init(ImportExprNode f) {
f.getScope() = any(Module m).getInitModule() and
(
f.getNode().getLevel() = 1 and
not exists(f.getNode().getName())
or
f.getNode().getImportedModuleName() = f.getEnclosingModule().getPackage().getName()
)
}
/** Gets the pseudo-object representing the value referred to by an undefined variable */ /** Gets the pseudo-object representing the value referred to by an undefined variable */
Object undefinedVariable() { py_special_objects(result, "_semmle_undefined_value") } Object undefinedVariable() { py_special_objects(result, "_semmle_undefined_value") }