Python: Adds modernized predicates

This commit is contained in:
Rebecca Valentine
2020-03-09 12:52:15 -07:00
parent 6636f72e07
commit 6a1203a60f

View File

@@ -269,6 +269,18 @@ class ExceptFlowNode extends ControlFlowNode {
)
}
private predicate handledObject(Value val, ClassValue cls, ControlFlowNode origin) {
val.getClass() = cls and
(
this.getType().pointsTo(val, origin)
or
exists(TupleValue tup |
this.handledObject(tup, ClassValue::tuple(), _) |
val = tup.getItem(_) and origin.pointsTo(val)
)
)
}
/** Gets the inferred type(s) that are handled by this node, splitting tuples if possible. */
pragma [noinline]
predicate handledException_objectapi(Object obj, ClassObject cls, ControlFlowNode origin) {
@@ -278,6 +290,15 @@ class ExceptFlowNode extends ControlFlowNode {
origin = this
}
/** Gets the inferred type(s) that are handled by this node, splitting tuples if possible. */
pragma [noinline]
predicate handledException(Value val, ClassValue cls, ControlFlowNode origin) {
this.handledObject(val, cls, origin) and not cls = ClassValue::tuple()
or
not exists(this.getNode().(ExceptStmt).getType()) and val = ClassValue::baseException() and cls = ClassValue::type() and
origin = this
}
/** Whether this `except` handles `cls` */
predicate handles(ClassObject cls) {
exists(ClassObject handled |