Python: Add AttrWrite.writes and AttrRead.reads

The latter of these is identical to `AttrRef.accesses`, but makes the
API a bit more intuitive.
This commit is contained in:
Taus
2025-08-08 12:56:28 +00:00
committed by Napalys Klicius
parent 8393ccf39d
commit 6f9e06c59e

View File

@@ -64,6 +64,15 @@ abstract class AttrRef extends Node {
abstract class AttrWrite extends AttrRef {
/** Gets the data flow node corresponding to the value that is written to the attribute. */
abstract Node getValue();
/**
* Holds if this attribute write writes the attribute named `attrName` on object `object` with
* value `value`.
*/
predicate writes(Node object, string attrName, Node value) {
this.accesses(object, attrName) and
this.getValue() = value
}
}
/**
@@ -225,7 +234,14 @@ private class ClassDefinitionAsAttrWrite extends AttrWrite, CfgNode {
* - Dynamic attribute reads using `getattr`: `getattr(object, attr)`
* - Qualified imports: `from module import attr as name`
*/
abstract class AttrRead extends AttrRef, Node, LocalSourceNode { }
abstract class AttrRead extends AttrRef, Node, LocalSourceNode {
/** Holds if this attribute read reads the attribute named `attrName` on the object `object`. */
predicate reads(Node object, string attrName) {
this.accesses(object, attrName)
}
}
/** A simple attribute read, e.g. `object.attr` */
private class AttributeReadAsAttrRead extends AttrRead, CfgNode {