Mutator that handles both statements and expressions
| 188 | |
| 189 | @tirx.functor.mutator |
| 190 | class ComplexMutator(PyStmtExprMutator): |
| 191 | """Mutator that handles both statements and expressions""" |
| 192 | |
| 193 | def __init__(self): |
| 194 | super().__init__() |
| 195 | self.modifications = 0 |
| 196 | |
| 197 | def visit_add_(self, op: Add): |
| 198 | self.modifications += 1 |
| 199 | # Convert a + b to a * 2 + b for demonstration |
| 200 | a = self.visit_expr(op.a) |
| 201 | b = self.visit_expr(op.b) |
| 202 | return Add(Mul(a, IntImm("int32", 2)), b) |
| 203 | |
| 204 | |
| 205 | def test_basic_visitor(): |
no outgoing calls
searching dependent graphs…