Python: Add IterableNode

I'm specifically not using an abstract class, since that is an anti-pattern:
https://github.com/github/codeql/pull/4357#discussion_r520526275 (I'm still
trying to wrap my head fully aroudn this)
This commit is contained in:
Rasmus Wriedt Larsen
2020-11-27 13:31:10 +01:00
parent 33e46e168f
commit 098f8c4f21

View File

@@ -772,6 +772,25 @@ class DictNode extends ControlFlowNode {
}
}
/**
* A control flow node corresponding to an iterable literal. Currently does not include
* dictionaries, use `DictNode` directly instead.
*/
class IterableNode extends ControlFlowNode {
IterableNode() {
this instanceof SequenceNode
or
this instanceof SetNode
}
/** Gets the control flow node for an element of this iterable. */
ControlFlowNode getAnElement() {
result = this.(SequenceNode).getAnElement()
or
result = this.(SetNode).getAnElement()
}
}
private AstNode assigned_value(Expr lhs) {
/* lhs = result */
exists(Assign a | a.getATarget() = lhs and result = a.getValue())