use tree_sitter::Node;
use super::VETO_KINDS;
pub(super) fn pure(n: Node) -> bool {
match n.kind() {
"integer" | "float" | "true" | "false" | "none" => true,
"string" => children_pure(n),
"string_content" | "escape_sequence" => true,
"list"
| "tuple"
| "set"
| "dictionary"
| "pair"
| "unary_operator"
| "binary_operator"
| "boolean_operator"
| "parenthesized_expression" => children_pure(n),
_ => false,
}
}
fn children_pure(n: Node) -> bool {
let mut c = n.walk();
n.children(&mut c)
.filter(|ch| ch.is_named())
.all(|ch| pure(ch))
}
pub(super) fn unconditionally_executed(write_node: Node) -> bool {
const OWNERS: [&str; 3] = ["function_definition", "class_definition", "lambda"];
let mut cur = Some(write_node);
while let Some(n) = cur {
if VETO_KINDS.contains(&n.kind()) {
return false;
}
if OWNERS.contains(&n.kind()) {
return true;
}
cur = n.parent();
}
true
}